Skip to content

Commit 232b132

Browse files
committed
Update bash-completion for arg-complete 0.2.0
1 parent bce9f92 commit 232b132

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

scripts/bash-completion.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,27 @@
66
# Permanent usage:
77
# Run: echo "source $(readlink -f .)/scripts/bash-completion.sh" >> ~/.bash_completion
88

9+
# Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
10+
# Copied & modified from standard __ltrim_colon_completions
11+
__ltrim_equal_completions()
12+
{
13+
if [[ $1 == *=* && $COMP_WORDBREAKS == *=* ]]; then
14+
# Remove equal-word prefix from COMPREPLY items
15+
local equal_word=${1%"${1##*=}"}
16+
local i=${#COMPREPLY[*]}
17+
while ((i-- > 0)); do
18+
COMPREPLY[i]=${COMPREPLY[i]#"$equal_word"}
19+
done
20+
fi
21+
}
22+
923
_goblint ()
1024
{
1125
IFS=$'\n'
12-
COMPREPLY=($(${COMP_WORDS[0]} --complete "${COMP_WORDS[@]:1:COMP_CWORD}"))
26+
local words cword cur
27+
_get_comp_words_by_ref -n = cur words cword # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
28+
COMPREPLY=($(${words[0]} --complete "${words[@]:1:cword}"))
29+
__ltrim_equal_completions "$cur" # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
1330
}
1431

1532
complete -o default -F _goblint goblint
@@ -26,7 +43,10 @@ _regtest ()
2643
COMPREPLY=($(ls -1 tests/regression/${COMP_WORDS[1]}-* | sed -n -r 's/([0-9][0-9])-.*/\1/p' | grep "^${COMP_WORDS[2]}"))
2744
;;
2845
*)
29-
COMPREPLY=($($(dirname ${COMP_WORDS[0]})/goblint --complete "${COMP_WORDS[@]:3:COMP_CWORD}"))
46+
local words cword cur
47+
_get_comp_words_by_ref -n = cur words cword # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
48+
COMPREPLY=($($(dirname ${words[0]})/goblint --complete "${words[@]:3:cword}"))
49+
__ltrim_equal_completions "$cur" # Bypass = in COMP_WORDBREAKS (https://stackoverflow.com/a/57437406/854540)
3050
;;
3151
esac
3252
}

0 commit comments

Comments
 (0)