Skip to content

Commit

Permalink
Fix bash completion with multiple file arguments (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
opoplawski committed Dec 5, 2023
1 parent 92c4885 commit 3d1b912
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions mock/etc/bash_completion.d/mock
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,35 @@ _mock_root()
_filedir 'cfg'
}

_mock_isopt()
{
[[ ${1:0:1} = - ]] && return 0
case $1 in
install|remove)
return 0
;;
esac
return 1
}

_mock()
{
local cur prev words cword split
_init_completion -s || return

local cfgdirs=( /etc/mock "$HOME/.config/mock" )
local count=0
local prevopt
for word in "${words[@]}" ; do
[[ $count -eq $cword ]] && break
if [[ $count -eq $cword ]] ; then
# If the last (i.e. current) argument is an option, clear prevopt so that we complete
# the current argument as an option instead an argument to prevopt
_mock_isopt "$word" && prevopt=
break
fi
# Record the option argument previous to the current argument to determine the type of
# completion that is needed
_mock_isopt "$word" && prevopt=$word
if [[ "$word" == --configdir ]] ; then
cfgdirs=( "${words[((count+1))]}" )
elif [[ "$word" == --configdir=* ]] ; then
Expand All @@ -40,7 +60,7 @@ _mock()
count=$((++count))
done

case "$prev" in
case "$prevopt" in
-h|--help|--version)
# no further arguments are accepted after the above arguments
return
Expand Down

0 comments on commit 3d1b912

Please sign in to comment.