Skip to content

Commit a586ede

Browse files
committed
unrar: make sure to include normal files in parts
_filedir looks unsuitable for this purpose since it gives no control to the prefix part, so I ended up calling compgen myself. Also altered the part matching pattern to be consistent with everyone else.
1 parent b045521 commit a586ede

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

completions/unrar

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
_unrar()
44
{
5-
local cur prev words cword cmp_opts=1 i
5+
local cur prev words cword cmp_opts=1 cmp_parts=0 i
66
_init_completion || return
77

88
# Check if all of the middle part are options.
@@ -25,12 +25,24 @@ _unrar()
2525
_filedir 'rar'
2626
# If there is a second, third, ... ninth part
2727
for i in "${COMPREPLY[@]}"; do
28-
if [[ i == *.part*(0)[2-9].[rR][aA][rR] ]]; then
29-
# Only look for the first, since it's the only useful one
30-
_filedir 'part*(0)1.rar'
28+
if [[ $i == *.part*(0)[2-9].@(rar|RAR) ]]; then
29+
cmp_parts=1
3130
break
3231
fi
3332
done
33+
if ((cmp_parts)); then
34+
local IFS=$'\n' set_f=0 quoted
35+
_quote_readline_by_ref "$cur" quoted
36+
[[ $- == *f* ]] && set_f=1
37+
set -f
38+
COMPREPLY=(
39+
$(compgen -d -- "$quoted")
40+
$(compgen -f \
41+
-X "!(!(.part+([0-9]))@(.part+(0)1|).@(rar|RAR))" -- \
42+
"$quoted")
43+
)
44+
((set_f)) || set +f
45+
fi
3446
else # files.../path...
3547
_filedir
3648
fi

0 commit comments

Comments
 (0)