10
10
local cur=${COMP_WORDS[COMP_CWORD]}
12
12
if [ "${cur:0:1}" = '-' ]; then
13
# looks like an option, return list of all options
14
COMPREPLY=( $( compgen -W "-E -f -g -h -l -o -q -r -R -t -T -v -V -z -Z -1 -2 -3 -4" -- $cur ) )
13
# ==> looks like an option, return list of all options
14
COMPREPLY=( $( compgen -W "-E -f -g -h -l -o -q -r -R -t -T -v -V -z -Z -1 -2 -3 -4" -- $cur) )
17
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
18
COMPREPLY[$i]="${COMPREPLY[$i]} "
15
20
elif [[ "${COMP_WORDS[$(( ${COMP_CWORD} - 1))]}" =~ '^-.*o$' ]]; then
16
# previous word contained -o, return list of plugouts
21
# ==> previous word contained -o, return list of output plugins
17
22
COMPREPLY=( $( compgen -W "$(gbsplay -o list 2>/dev/null | ( read; cut -d - -f 1 )) list" -- $cur ) )
25
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
26
COMPREPLY[$i]="${COMPREPLY[$i]} "
19
29
# calculate position of filename
21
31
while [ "${COMP_WORDS[filepos]:0:1}" = '-' ]; do
22
if [[ "${COMP_WORDS[$(( filepos ))]}" =~ '^-.*o$' ]]; then
32
if [[ "${COMP_WORDS[$filepos]}" =~ '^-.*o$' ]]; then
23
33
# jump over parameter to -o
28
38
if [ $(( $COMP_CWORD - $filepos )) -eq 0 ] ; then
29
# this is the filename
30
COMPREPLY=( $( compgen -f -X '!*.gbs' -- $cur) $(compgen -d -o dirnames -- $cur ))
39
# ==> this is the filename
42
# add trailing space to filenames
44
files=( $( compgen -f -X '!*.gbs' -- $cur ) ) # does not work: | sed -e 's/\([[:space:]]\)/\\\1/g'
45
for (( i=0; i < ${#files[@]}; i++ )); do
46
COMPREPLY[${#COMPREPLY[@]}]="${files[$i]} "
48
# add trailing slash to directories
50
dirs=( $( compgen -d -- $cur ) )
51
for (( i=0; i < ${#dirs[@]}; i++ )); do
52
COMPREPLY[${#COMPREPLY[@]}]="${dirs[$i]}/"
31
54
elif [ $(( $COMP_CWORD - $filepos )) -eq 1 ] ; then
32
# this is the subsong start
55
# ==> this is the subsong start
33
56
COMPREPLY=( $( compgen -W "$(seq $(gbsinfo ${COMP_WORDS[filepos]} 2>/dev/null | grep ^Subsongs | cut -d: -f 2) 2>/dev/null)" -- $cur ) )
59
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
60
COMPREPLY[$i]="${COMPREPLY[$i]} "
34
62
elif [ $(( $COMP_CWORD - $filepos )) -eq 2 ] ; then
35
# this is the subsong stop...
63
# ==> this is the subsong stop...
36
64
if [[ ${COMP_WORDS[COMP_CWORD - 1]} =~ '^[0-9]+$' ]] ; then
37
65
# ...but only if subsong start was given before
38
66
COMPREPLY=( $( compgen -W "$(seq $(gbsinfo ${COMP_WORDS[filepos]} 2>/dev/null | grep ^Subsongs | cut -d: -f 2) 2>/dev/null)" -- $cur ) )
69
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
70
COMPREPLY[$i]="${COMPREPLY[$i]} "
47
80
local cur=${COMP_WORDS[COMP_CWORD]}
49
82
if [ "${cur:0:1}" = '-' ]; then
50
# looks like an option, return list of all options
51
COMPREPLY=( $( compgen -W "-h -V" -- $cur ) )
83
# ==> looks like an option, return list of all options
84
COMPREPLY=( $( compgen -W "-h -V" -- $cur) )
87
for (( i=0; i < ${#COMPREPLY[@]}; i++ )); do
88
COMPREPLY[$i]="${COMPREPLY[$i]} "
53
91
# calculate position of filename
58
96
if [ $(( $COMP_CWORD - $filepos )) -eq 0 ] ; then
59
# this is the filename
60
COMPREPLY=( $( compgen -f -X '!*.gbs' -- $cur) $(compgen -d -o dirnames -- $cur ))
97
# ==> this is the filename
100
# add trailing space to filenames
102
files=( $( compgen -f -X '!*.gbs' -- $cur ) ) # does not work: | sed -e 's/\([[:space:]]\)/\\\1/g'
103
for (( i=0; i < ${#files[@]}; i++ )); do
104
COMPREPLY[${#COMPREPLY[@]}]="${files[$i]} "
106
# add trailing slash to directories
108
dirs=( $( compgen -d -- $cur ) )
109
for (( i=0; i < ${#dirs[@]}; i++ )); do
110
COMPREPLY[${#COMPREPLY[@]}]="${dirs[$i]}/"
65
complete -F _gbsplay -o plusdirs gbsplay
66
complete -F _gbsinfo -o plusdirs gbsinfo
116
complete -F _gbsplay -o default -o nospace gbsplay
117
complete -F _gbsinfo -o default -o nospace gbsinfo