generated from 8dcc/c-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbin-graph-completion.bash
More file actions
45 lines (40 loc) · 1.19 KB
/
bin-graph-completion.bash
File metadata and controls
45 lines (40 loc) · 1.19 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
#!/usr/bin/env bash
_bin_graph_completion() {
local arg_opts nonarg_opts
arg_opts=(
-m --mode
-w --width
-z --zoom
--block-size
--offset-start --offset-end
--output-format
--transform-squares
)
nonarg_opts=(
-h --help
--list-modes
--list-output-formats
)
# If the previous option ('$3') is a redirector, show the default file
# completion.
if [[ "$3" == '2>' || "$3" == '>' || "$3" == '<' ]]; then
compopt -o bashdefault -o default
return
fi
# If the previous option expected an extra parameter, don't show completion.
for arg in "${arg_opts[@]}"; do
if [ "$3" = "$arg" ]; then
return
fi
done
if [[ "$2" = -* ]]; then
# If the current option ('$2') starts with a dash, return (in
# '$COMPREPLY') the possible completions for the current option using
# 'compgen'.
mapfile -t COMPREPLY < <(compgen -W "${arg_opts[*]} ${nonarg_opts[*]}" -- "$2")
else
# Otherwise, show the default file completion.
compopt -o bashdefault -o default
fi
}
complete -F _bin_graph_completion bin-graph