-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_completion.bash
52 lines (46 loc) · 1.2 KB
/
bash_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
# This script registers the bash auto completion for GM2Calc's main
# program gm2calc.x.
#
# Usage:
#
# . bash_completions.bash
_gm2calc()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="
--gm2calc-input-file=
--slha-input-file=
--thdm-input-file=
--help
--version
"
# handle --xxxxxx=
if [[ ${prev} == "--"* && ${cur} == "=" ]] ; then
compopt -o filenames
COMPREPLY=(*)
return 0
fi
# handle --xxxxx=path
if [[ ${prev} == '=' ]] ; then
# unescape space
cur=${cur//\\ / }
# expand tilde to $HOME
[[ ${cur} == "~/"* ]] && cur=${cur/\~/$HOME}
# show completion if path exist (and escape spaces)
compopt -o filenames
local files=("${cur}"*)
[[ -e ${files[0]} ]] && COMPREPLY=( "${files[@]// /\ }" )
return 0
fi
# handle other options
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != "--"*"=" ]] ; then
# if there's only one option, without =, then allow a space
compopt +o nospace
fi
return 0
}
complete -o nospace -F _gm2calc gm2calc.x