-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtfm.bash_completion
More file actions
58 lines (49 loc) · 1.57 KB
/
rtfm.bash_completion
File metadata and controls
58 lines (49 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
# Bash completion for rtfm
# Source this file or copy to /etc/bash_completion.d/rtfm
_rtfm() {
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# Options from the rtfm script
opts="-r --rebuild-lists --install --update -v --verbose -q --quiet -V --version -h --help --"
# Check if -- separator has been used (everything after is a command name)
local -i i past_separator=0
for ((i = 1; i < COMP_CWORD; i++)); do
[[ ${COMP_WORDS[i]} == -- ]] && past_separator=1
done
# Terminal options: these actions exit immediately, no further arguments needed
if ! ((past_separator)); then
case "$prev" in
-r|--rebuild-lists|--install|--update|-V|--version|-h|--help)
return 0
;;
esac
fi
# If current word starts with dash and we haven't passed --, complete with options
if [[ "$cur" == -* ]] && ! ((past_separator)); then
mapfile -t COMPREPLY < <(compgen -W "$opts" -- "$cur")
return 0
fi
# Complete with available commands from rtfm lists
local -- commands=''
local -a list_files=(
/usr/local/share/rtfm/builtin.list
/usr/local/share/rtfm/man.list
/usr/local/share/rtfm/info.list
/usr/local/share/rtfm/tldr.list
)
local -- file
for file in "${list_files[@]}"; do
[[ -f "$file" ]] && commands+=" $(<"$file")"
done
# Remove duplicates and complete
if [[ -n "$commands" ]]; then
mapfile -t COMPREPLY < <(compgen -W "$commands" -- "$cur" | sort -u)
fi
return 0
}
# Register the completion function
complete -F _rtfm rtfm
#fin