-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcmdshelf-completion.bash
executable file
·56 lines (45 loc) · 1.46 KB
/
cmdshelf-completion.bash
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
# Bash completion script for cmdshelf.
_cmdshelf() {
local commands command cur prev
commands="cat list ls remote run update"
command="${COMP_WORDS[1]}"
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ $COMP_CWORD == 1 ]
then
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
fi
if [ $COMP_CWORD == 2 -a "${command}" == help ]
then
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
fi
case "${command}" in
remote)
COMPREPLY=($(compgen -W 'add list remove' -- ${cur}))
return 0
;;
list|ls)
COMPREPLY=($(compgen -W '--path' -- "${cur}"))
return 0
;;
run)
if [ $COMP_CWORD -le 2 ]; then
COMPREPLY=($(compgen -W "$(cmdshelf list | awk -F: '{print $2}')" -- "${cur}"))
else
# NOTE: available on bash 4 or later
compopt -o filenames cmdshelf 2>/dev/null
compgen -f /non-existing-dir/ >/dev/null
COMPREPLY=($(compgen -df -- "$cur"))
fi
return 0
;;
cat)
COMPREPLY=($(compgen -W "$(cmdshelf list | awk -F: '{print $2}')" -- "${cur}"))
return 0
;;
esac
}
# https://www.gnu.org/software/bash/manual/html_node/A-Programmable-Completion-Example.html
complete -o bashdefault -F _cmdshelf cmdshelf