Skip to content

Commit 169dc2d

Browse files
committed
bash completion: expand both *.gbs and *.gbs.gz
Also don't list directories ending with .gbs or .gbs.gz as both file and directory names. Once as directory (with a trailing slash) is enough.
1 parent 828d5be commit 169dc2d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

contrib/gbsplay.bashcompletion

+18-7
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,43 @@ __gbsplay_add_spaces_to_compreply()
1717
}
1818

1919
__gbsplay_expand_filename()
20-
# TODO/CHECK: do all file extensions work (eg .gbs.gz)?
2120
{
2221
COMPREPLY=()
23-
local i
22+
local i ext
2423

25-
# add trailing space to filenames
2624
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+
3037
done
3138

32-
# add trailing slash to directories
39+
# get all matching directories
3340
local -a dirs
3441
mapfile -t dirs < <( compgen -d -- "$cur" )
42+
43+
# add trailing slash to directories
3544
for (( i=0; i < ${#dirs[@]}; i++ )); do
3645
COMPREPLY[${#COMPREPLY[@]}]="${dirs[$i]}/"
3746
done
3847
}
3948

4049
__gbsplay_return_empty_completion()
50+
# FIXME: empty COMPREPLY seems to fall back to default filename completion - how can we avoid that?
4151
{
4252
COMPREPLY=()
4353
}
4454

4555
__gbsplay()
56+
# FIXME: gbsinfo don't do tilde expansion, eg. '~/foo.gbs' as a filename won't be found
4657
{
4758
local cur=${COMP_WORDS[COMP_CWORD]}
4859
local prev=${COMP_WORDS[$(( COMP_CWORD - 1))]}

0 commit comments

Comments
 (0)