Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash completions #563

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions bash_completion.d/clush
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# clush bash completion
#
# to install in /usr/share/bash-completion/completions/ or ~/.local/share/bash-completion/completions/
_clush()
{
# shellcheck disable=SC2034 # set/used by _init_completion
local cur prev words cword split
local word options="" skip=argv0 groupsource=""

_init_completion -s -n : || return

# stop parsing if there had been any non-option before (or --)
for word in "${words[@]}"; do
case "$skip" in
"") ;;
groupsource)
groupsource="$word"
;& # fallthrough
*)
skip=""
continue
;;
esac
case "$word" in
"") ;;
--) return;;
# no-arg options
--version|-h|--help|-n|--nostdin|-a|--all|-q|--quiet|\
-v|--verbose|-d|--debug) ;;
# get source separately...
--groupsource=*) groupsource="${word#*=}";;
-s|--groupsource) skip=groupsource;;
# assume all the rest as options...
# options with = included in word
--*=*) ;;
-*) skip=any;;
*) return;; # was non-option
esac
done

case "$prev" in
-w|-x)
options="$(cluset ${groupsource:+-s "$groupsource"} -L 2>/dev/null)"
;;
_g|--group|-X)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(typo) _ -> -

options="$(cluset ${groupsource:+-s "$groupsource"} -L 2>/dev/null | sed -e 's/^@//')"
;;
-s|--groupsource)
options=$(cluset --groupsources | sed -e 's/ (default)//')
;;
--color)
options="never always auto"
;;
-R|--worker)
options="ssh exec rsh"
;;
# no-arg options
--version|-h|--help|-n|--nostdin|-a|--all|-q|--quiet|\
-v|--verbose|-d|--debug) ;;
# any other option: just ignore.
-*)
return;;
esac
# get all options from help text... not 100% accurate but good enough.
[ -n "$options" ] || options="$(clush --help | grep -oP -- '(?<=[ \t])(-[a-z]|--[^= \t]*)')"

mapfile -t COMPREPLY < <(compgen -W "$options" -- "$cur")
# remove the prefix from COMPREPLY if $cur contains colons and
# COMP_WORDBREAKS splits on colons...
__ltrim_colon_completions "$cur"
} && complete -F _clush clush
2 changes: 1 addition & 1 deletion lib/ClusterShell/CLI/Nodeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def command_list(options, xset, group_resolver):
# useful: sources[0] is always the default or selected source
sources = group_resolver.sources()
# do not print name of default group source unless -s specified
if sources and not options.groupsource:
if sources:
sources[0] = None
else:
sources = [options.groupsource]
Expand Down
Loading