-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash_complete
More file actions
114 lines (114 loc) · 3.31 KB
/
bash_complete
File metadata and controls
114 lines (114 loc) · 3.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Script autocomplete of sam
# bash completion file for sam subcommands
#
# This script provides supports completion of:
# - command options
# - app and version names
# - image repos and tags
# - filepaths
#
# To enable the completions either:
# - place this file in /etc/bash_completion.d
# or
# - copy this file and add the line below to your .bashrc after
# bash completion features are loaded
# . sam_autocomplete
#
# Note:
# Currently, the completions will not work if
# not started subcommand 'sam search'
#
# example from /etc/bash_completion.d/docker.io
#
_sam_in()
{
local hist='/var/db/sam/history'
local apps="$(cat $hist)"
COMPREPLY=( $( compgen -W "$apps" -- "$cur" ) )
}
#
_sam_rm()
{
local names=$(sam list --raw | awk -F '|' '{print $1 ":" $2}')
COMPREPLY=( $( compgen -W "$names" -- "$cur" ) )
}
#
_sam_info()
{
local hist='/var/db/sam/history'
local apps="$(cat $hist)"
COMPREPLY=( $( compgen -W "$apps" -- "$cur" ) )
}
#
_sam_se()
{
local hist='/var/db/sam/history'
local names=$(cat $hist | awk -F ':' '{print $1}' | uniq)
COMPREPLY=( $( compgen -W "$names" -- "$cur" ) )
}
#
_sam()
{
local commands="
help
install
remove
list
search
info
upgrade
addrepo
removerepo
modifyrepo
listrepos
purge
"
local addcommands="
in
rm
se
up
ar
rr
mr
lr
"
#
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[COMP_CWORD-1]}
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
COMPREPLY=()
#
case "${COMP_WORDS[COMP_CWORD]}" in
-*) COMPREPLY=( $(compgen -W '--debug --help' -- $cur) )
return 0
;;
*)
if [[ -z "`echo $commands$addcommands | grep $prev`" ]];then
COMPREPLY=( $(compgen -W "$commands" -- $cur) )
return 0
else
if [[ "$prev" == 'in' || "$prev" == 'install' ]];then
_sam_in;
return 0
fi;
if [[ "$prev" == 'rm' || "$prev" == 'remove' ]];then
_sam_rm;
return 0
fi;
if [[ "$prev" == 'se' || "$prev" == 'search' ]];then
_sam_se;
return 0
fi;
if [[ "$prev" == 'info' ]];then
_sam_info;
return 0
fi;
COMPREPLY=()
return 0
fi;
esac
return 0
}
complete -F _sam sam
# End script autocomplete