@@ -17,32 +17,43 @@ __gbsplay_add_spaces_to_compreply()
17
17
}
18
18
19
19
__gbsplay_expand_filename ()
20
- # TODO/CHECK: do all file extensions work (eg .gbs.gz)?
21
20
{
22
21
COMPREPLY=()
23
- local i
22
+ local i ext
24
23
25
- # add trailing space to filenames
26
24
local -a files
27
- mapfile -t files < <( compgen -f -X ' !*.gbs' -- " $cur " ) # does not work: | sed -e 's/\([[:space:]]\)/\\\1/g'
28
- for (( i= 0 ; i < ${# files[@]} ; i++ )) ; do
29
- COMPREPLY[${# COMPREPLY[@]} ]=" ${files[$i]} "
25
+ for ext in .gbs .gbs.gz; do
26
+
27
+ # get all matching files ending with $ext
28
+ mapfile -t files < <( compgen -f -X " !*$ext " -- " $cur " )
29
+
30
+ # add trailing space to filenames
31
+ for (( i= 0 ; i < ${# files[@]} ; i++ )) ; do
32
+ if ! [ -d " ${files[$i]} " ]; then # prevent directories from also showing up as files
33
+ COMPREPLY[${# COMPREPLY[@]} ]=" ${files[$i]} "
34
+ fi
35
+ done
36
+
30
37
done
31
38
32
- # add trailing slash to directories
39
+ # get all matching directories
33
40
local -a dirs
34
41
mapfile -t dirs < <( compgen -d -- " $cur " )
42
+
43
+ # add trailing slash to directories
35
44
for (( i= 0 ; i < ${# dirs[@]} ; i++ )) ; do
36
45
COMPREPLY[${# COMPREPLY[@]} ]=" ${dirs[$i]} /"
37
46
done
38
47
}
39
48
40
49
__gbsplay_return_empty_completion ()
50
+ # FIXME: empty COMPREPLY seems to fall back to default filename completion - how can we avoid that?
41
51
{
42
52
COMPREPLY=()
43
53
}
44
54
45
55
__gbsplay ()
56
+ # FIXME: gbsinfo don't do tilde expansion, eg. '~/foo.gbs' as a filename won't be found
46
57
{
47
58
local cur=${COMP_WORDS[COMP_CWORD]}
48
59
local prev=${COMP_WORDS[$(( COMP_CWORD - 1))]}
0 commit comments