forked from DataBiosphere/dsub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_tab_complete
64 lines (52 loc) · 1.23 KB
/
bash_tab_complete
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
# To use, in the Bash shell:
# source bash_tab_complete
#
# Then you can use the "tab" key to auto-complete options in the
# command line for dsub, dstat, or ddel.
#
# dsub --pro<TAB>
# dsub --project
#
# If you update dsub or related tools, you can source this file again
# to update the tab completion rules.
declare -A cmdline_options_for_dstar
cmdline_options_for_dstar[dstat]=""
cmdline_options_for_dstar[dsub]=""
cmdline_options_for_dstar[ddel]=""
_find_options_for()
{
local tool="$1"
2>&1 "$tool" | grep -oe '\-[a-zA-Z_\-]*' | sort | uniq | xargs
}
_go_with_options()
{
local options="$@"
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
return 0
}
_magic_options_for()
{
local tool="$1"
local tool_path="$2"
if [ -z "${cmdline_options_for_dstar[$tool]}" ]; then
cmdline_options_for_dstar[$tool]="$(_find_options_for $tool_path)"
fi
_go_with_options "${cmdline_options_for_dstar[$tool]}"
}
_dsub()
{
_magic_options_for "dsub" "$1"
}
_dstat()
{
_magic_options_for "dstat" "$1"
}
_ddel()
{
_magic_options_for "ddel" "$1"
}
complete -o default -F _dsub dsub
complete -o default -F _dstat dstat
complete -o default -F _ddel ddel