From 153d80e9189ba8f10d93379956593f4984a91ca7 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Mon, 1 Jul 2024 05:46:38 +0900 Subject: [PATCH 1/2] nodeset: do not list selected source prefix for -L If a source is selected with -s for cluset -L then we correctly list it first, but there is no need to print the prefix --- lib/ClusterShell/CLI/Nodeset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ClusterShell/CLI/Nodeset.py b/lib/ClusterShell/CLI/Nodeset.py index 3c74268d..9f001615 100755 --- a/lib/ClusterShell/CLI/Nodeset.py +++ b/lib/ClusterShell/CLI/Nodeset.py @@ -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] From e738d0cdb3c3444552ca3a9fc4c20ccf4673d4ea Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Mon, 1 Jul 2024 07:41:49 +0900 Subject: [PATCH 2/2] WIP: bash completions just clush for now --- bash_completion.d/clush | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 bash_completion.d/clush diff --git a/bash_completion.d/clush b/bash_completion.d/clush new file mode 100644 index 00000000..6efcadf7 --- /dev/null +++ b/bash_completion.d/clush @@ -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) + 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