-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgxt_completion
43 lines (36 loc) · 1.32 KB
/
gxt_completion
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
#-*- mode: shell-script;-*-
# bash_completion
# Giap Tran <txgvnn@gmail.com>
# github.com/TxGVNN/gxt
GXTDIR=${GXTDIR:-"$HOME/.gxt"}
_gxt(){
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands="--help --version help new add init list log vi em stat ls rm mv share search export gpg"
if [ $COMP_CWORD == 1 ]
then
COMPREPLY=($(compgen -W "${commands}" -- ${cur}))
return 0
fi
if [ $COMP_CWORD == 2 ]; then
case "$prev" in
"vi"|"em"|"cat"|"more"|"less"|"stat"|"rm"|"delete"|"log"|"share"|"mv"|"export")
local box_list=$(find "$GXTDIR/" -path "*.git" -prune -o -type f -print | sed 's,'"$GXTDIR/"',,g')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
"add")
local box_list=$(find . -mindepth 1 -maxdepth 1 -type f -exec basename {} \;)
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
"list"|"ls")
local box_list=$(find "$GXTDIR/" -path "*.git" -prune -o -type d -print | sed 's,'"$GXTDIR/"',,g')
COMPREPLY=($(compgen -W "${box_list}" -- ${cur}))
return 0
;;
*) ;;
esac
fi
}
complete -F _gxt gxt