Skip to content

Commit

Permalink
*: Comma separated opt arg completion improvements
Browse files Browse the repository at this point in the history
When completing comma separated lists, display the new argument
suggestions to be added as is, instead of prefixing them with
"oldarguments,". So suggest "bar" instead of "foo,bar" after "foo," (the
existing "foo," prefix will be kept once there is only one option to
complete).
  • Loading branch information
scop committed Feb 2, 2018
1 parent c71f5fc commit 021058b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
5 changes: 4 additions & 1 deletion completions/kcov
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ _kcov()
if [[ "$cur" == ?*,* ]]; then
prev="${cur%,*}"
cur="${cur##*,}"
COMPREPLY=( $( compgen -P "$prev," -W "{0..100}" -- "$cur" ) )
COMPREPLY=( $( compgen -W "{0..100}" -- "$cur" ) )
[[ ${#COMPREPLY[@]} -eq 1 ]] && \
COMPREPLY=( ${COMPREPLY/#/$prev,} )
else
COMPREPLY=( $( compgen -W "{0..100}" -- "$cur" ) )
[[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/%/,} )
compopt -o nospace
fi
return
Expand Down
2 changes: 1 addition & 1 deletion completions/pylint
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _pylint()
local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
cur="${cur##*,}"
_xfunc python _python_modules $python
COMPREPLY=( ${COMPREPLY[@]/#/$prefix} )
[[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
return
;;
-f|--format)
Expand Down
3 changes: 2 additions & 1 deletion completions/ss
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ _ss()
;;
-A|--query)
local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
COMPREPLY=( $( compgen -P "$prefix" -W '$( "$1" --help | \
COMPREPLY=( $( compgen -W '$( "$1" --help | \
command sed -e "s/|/ /g" -ne "s/.*QUERY := {\([^}]*\)}.*/\1/p" )' \
-- "${cur##*,}" ) )
[[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
return
;;
-D|--diag|-F|--filter)
Expand Down
4 changes: 2 additions & 2 deletions completions/tshark
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ _tshark()
;;
-O)
local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
COMPREPLY=( $( compgen -P "$prefix" -W \
"$( "$1" -G protocols 2>&1 | cut -f 3 )" \
COMPREPLY=( $( compgen -W "$( "$1" -G protocols 2>&1 | cut -f 3 )" \
-- "${cur##*,}" ) )
[[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
return
;;
-T)
Expand Down
3 changes: 2 additions & 1 deletion completions/useradd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ _useradd()
;;
-G|--groups)
local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
COMPREPLY=( $( compgen -P "$prefix" -g -- "${cur##*,}" ) )
COMPREPLY=( $( compgen -g -- "${cur##*,}" ) )
[[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
return
;;
-s|--shell)
Expand Down
3 changes: 2 additions & 1 deletion completions/usermod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ _usermod()
;;
-G|--groups)
local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
COMPREPLY=( $( compgen -P "$prefix" -g -- "${cur##*,}" ) )
COMPREPLY=( $( compgen -g -- "${cur##*,}" ) )
[[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
return
;;
-R|--root)
Expand Down
6 changes: 2 additions & 4 deletions test/lib/completions/kcov.exp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ setup


assert_complete_any "kcov "


sync_after_int


set test "--exclude-patter<TAB> should complete \"--exclude-pattern=\""
assert_complete "--exclude-pattern=" "kcov --exclude-patter" $test -nospace
sync_after_int


assert_complete_any "kcov -l 42,"
sync_after_int


Expand Down
3 changes: 3 additions & 0 deletions test/lib/completions/ss.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ sync_after_int
assert_complete_any "ss -A "
sync_after_int

assert_complete_any "ss -A foo,"
sync_after_int


teardown
3 changes: 3 additions & 0 deletions test/lib/completions/tshark.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ sync_after_int
assert_complete_any "tshark -G "
sync_after_int

assert_complete_any "tshark -O foo,htt"
sync_after_int


teardown

0 comments on commit 021058b

Please sign in to comment.