Skip to content

Commit 05d012f

Browse files
authored
completion: handle short opts without spaces (#586)
Apparently some people want to use clush -wfoo...
1 parent 288b582 commit 05d012f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

bash_completion.d/clush

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ _clush_command_or_file() {
55
# undo our nospace setting...
66
compopt +o nospace
77

8+
# skip if shortopt is set -- these helpers cannot "restore" shortopt at start of
9+
# the completions they provide easily
10+
[ -n "$shortopt" ] && return
11+
812
# complete either files (copy mode) or commands (if target set)
913
case "$target_set,$mode" in
1014
*,copy)
@@ -32,6 +36,7 @@ _clush()
3236
local cur prev words cword split
3337
local i word options="" compopts="" skip=argv0 groupsource="" cleangroup=""
3438
local mode=command target_set=""
39+
local shortopt=""
3540

3641
_init_completion -s -n : || return
3742

@@ -76,6 +81,15 @@ _clush()
7681
esac
7782
done
7883

84+
# split short opts without space...
85+
case "$cur" in
86+
-[a-z]*)
87+
shortopt="${cur:0:2}"
88+
prev="$shortopt"
89+
cur="${cur:2}"
90+
;;
91+
esac
92+
7993
case "$prev" in
8094
-w|-x|-g|--group|-X)
8195
case "$cur" in
@@ -134,7 +148,9 @@ _clush()
134148
fi
135149

136150
# append space for everything that doesn't end in `:` (likely a groupsource)
137-
mapfile -t COMPREPLY < <(compgen -W "$options" -- "$cur" | sed -e 's/[^:]$/& /')
151+
mapfile -t COMPREPLY \
152+
< <(compgen -W "$options" -- "$cur" \
153+
| sed -e 's/[^:]$/& /' -e "s/^/$shortopt/")
138154
# remove the prefix from COMPREPLY if $cur contains colons and
139155
# COMP_WORDBREAKS splits on colons...
140156
__ltrim_colon_completions "$cur"

0 commit comments

Comments
 (0)