Re: [systemd-devel] [PATCH 11/11] Make redirections work with the bash command completions
On Mon, Jun 16, 2014 at 02:59:34PM +0200, Dr. Werner Fink wrote: On Fri, Jun 13, 2014 at 07:09:50PM +0300, Ran Benita wrote: From a cursory look, the bash-completion package deals with this issue in a more systematic way. See _init_completion() in /usr/share/bash-completion/bash_completion. Maybe it's worthwhile to (conditionally?) use that if possible. Yes! I didn't know that this exists... We should make use of it if it is available. Hmmm ... I'd like not to loose the possibility to use completions for e.g. systemctl without having bash-completion installed. This because there *are* users out here which do *not* use nor install bash-completion package (or deinstall bash-completion). And I do not speak for my person as I use bash-completion but as a package maintainer. IMHO my patch is correct and allow to redirect the output of e.g. systemctl status. This patch works only for one type of redirection... Too much of a hack, especially that we have the full solution ready for us. Zbyszek ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH 11/11] Make redirections work with the bash command completions
On Fri, Jun 13, 2014 at 07:09:50PM +0300, Ran Benita wrote: From a cursory look, the bash-completion package deals with this issue in a more systematic way. See _init_completion() in /usr/share/bash-completion/bash_completion. Maybe it's worthwhile to (conditionally?) use that if possible. Hmmm ... I'd like not to loose the possibility to use completions for e.g. systemctl without having bash-completion installed. This because there *are* users out here which do *not* use nor install bash-completion package (or deinstall bash-completion). And I do not speak for my person as I use bash-completion but as a package maintainer. IMHO my patch is correct and allow to redirect the output of e.g. systemctl status. Werner On Fri, Jun 13, 2014 at 04:41:10PM +0200, Werner Fink wrote: --- shell-completion/bash/hostnamectl |6 +- shell-completion/bash/journalctl |6 +- shell-completion/bash/kernel-install | 13 - shell-completion/bash/localectl |6 +- shell-completion/bash/loginctl|6 +- shell-completion/bash/systemctl |6 +- shell-completion/bash/systemd-analyze |6 +- shell-completion/bash/systemd-coredumpctl |6 +- shell-completion/bash/systemd-run | 14 +- shell-completion/bash/timedatectl |6 +- shell-completion/bash/udevadm |6 +- 11 files changed, 70 insertions(+), 11 deletions(-) diff --git shell-completion/bash/hostnamectl shell-completion/bash/hostnamectl index 9c75da9..2e947f6 100644 --- shell-completion/bash/hostnamectl +++ shell-completion/bash/hostnamectl @@ -30,6 +30,10 @@ _hostnamectl() { local OPTS='-h --help --version --transient --static --pretty --no-ask-password -H --host' +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if [[ $cur = -* ]]; then COMPREPLY=( $(compgen -W '${OPTS[*]}' -- $cur) ) return 0 @@ -58,4 +62,4 @@ _hostnamectl() { return 0 } -complete -F _hostnamectl hostnamectl +complete -o default -o bashdefault -F _hostnamectl hostnamectl diff --git shell-completion/bash/journalctl shell-completion/bash/journalctl index e4b2f4a..50f83e0 100644 --- shell-completion/bash/journalctl +++ shell-completion/bash/journalctl @@ -49,6 +49,10 @@ _journalctl() { --verify-key' ) +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then case $prev in --boot|--this-boot|-b) @@ -111,4 +115,4 @@ _journalctl() { fi } -complete -F _journalctl journalctl +complete -o default -o bashdefault -F _journalctl journalctl diff --git shell-completion/bash/kernel-install shell-completion/bash/kernel-install index 7cd2494..33cf27c 100644 --- shell-completion/bash/kernel-install +++ shell-completion/bash/kernel-install @@ -18,11 +18,22 @@ # You should have received a copy of the GNU Lesser General Public License # along with systemd; If not, see http://www.gnu.org/licenses/. +__contains_word () { +local w word=$1; shift +for w in $@; do +[[ $w = $word ]] return +done +} + _kernel_install() { local comps local MACHINE_ID local cur=${COMP_WORDS[COMP_CWORD]} +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + case $COMP_CWORD in 1) comps=add remove @@ -47,4 +58,4 @@ _kernel_install() { return 0 } -complete -F _kernel_install kernel-install +complete -o default -o bashdefault -F _kernel_install kernel-install diff --git shell-completion/bash/localectl shell-completion/bash/localectl index c9e22af..3150f87 100644 --- shell-completion/bash/localectl +++ shell-completion/bash/localectl @@ -36,6 +36,10 @@ _localectl() { local OPTS='-h --help --version --no-convert --no-pager --no-ask-password -H --host' +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev $OPTS; then case $prev in --host|-H) @@ -89,4 +93,4 @@ _localectl() { return 0 } -complete -F _localectl localectl +complete -o default -o bashdefault -F _localectl localectl diff --git shell-completion/bash/loginctl shell-completion/bash/loginctl index e7adb93..9b137b4 100644 --- shell-completion/bash/loginctl +++ shell-completion/bash/loginctl @@
[systemd-devel] [PATCH 11/11] Make redirections work with the bash command completions
--- shell-completion/bash/hostnamectl |6 +- shell-completion/bash/journalctl |6 +- shell-completion/bash/kernel-install | 13 - shell-completion/bash/localectl |6 +- shell-completion/bash/loginctl|6 +- shell-completion/bash/systemctl |6 +- shell-completion/bash/systemd-analyze |6 +- shell-completion/bash/systemd-coredumpctl |6 +- shell-completion/bash/systemd-run | 14 +- shell-completion/bash/timedatectl |6 +- shell-completion/bash/udevadm |6 +- 11 files changed, 70 insertions(+), 11 deletions(-) diff --git shell-completion/bash/hostnamectl shell-completion/bash/hostnamectl index 9c75da9..2e947f6 100644 --- shell-completion/bash/hostnamectl +++ shell-completion/bash/hostnamectl @@ -30,6 +30,10 @@ _hostnamectl() { local OPTS='-h --help --version --transient --static --pretty --no-ask-password -H --host' +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if [[ $cur = -* ]]; then COMPREPLY=( $(compgen -W '${OPTS[*]}' -- $cur) ) return 0 @@ -58,4 +62,4 @@ _hostnamectl() { return 0 } -complete -F _hostnamectl hostnamectl +complete -o default -o bashdefault -F _hostnamectl hostnamectl diff --git shell-completion/bash/journalctl shell-completion/bash/journalctl index e4b2f4a..50f83e0 100644 --- shell-completion/bash/journalctl +++ shell-completion/bash/journalctl @@ -49,6 +49,10 @@ _journalctl() { --verify-key' ) +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then case $prev in --boot|--this-boot|-b) @@ -111,4 +115,4 @@ _journalctl() { fi } -complete -F _journalctl journalctl +complete -o default -o bashdefault -F _journalctl journalctl diff --git shell-completion/bash/kernel-install shell-completion/bash/kernel-install index 7cd2494..33cf27c 100644 --- shell-completion/bash/kernel-install +++ shell-completion/bash/kernel-install @@ -18,11 +18,22 @@ # You should have received a copy of the GNU Lesser General Public License # along with systemd; If not, see http://www.gnu.org/licenses/. +__contains_word () { +local w word=$1; shift +for w in $@; do +[[ $w = $word ]] return +done +} + _kernel_install() { local comps local MACHINE_ID local cur=${COMP_WORDS[COMP_CWORD]} +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + case $COMP_CWORD in 1) comps=add remove @@ -47,4 +58,4 @@ _kernel_install() { return 0 } -complete -F _kernel_install kernel-install +complete -o default -o bashdefault -F _kernel_install kernel-install diff --git shell-completion/bash/localectl shell-completion/bash/localectl index c9e22af..3150f87 100644 --- shell-completion/bash/localectl +++ shell-completion/bash/localectl @@ -36,6 +36,10 @@ _localectl() { local OPTS='-h --help --version --no-convert --no-pager --no-ask-password -H --host' +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev $OPTS; then case $prev in --host|-H) @@ -89,4 +93,4 @@ _localectl() { return 0 } -complete -F _localectl localectl +complete -o default -o bashdefault -F _localectl localectl diff --git shell-completion/bash/loginctl shell-completion/bash/loginctl index e7adb93..9b137b4 100644 --- shell-completion/bash/loginctl +++ shell-completion/bash/loginctl @@ -37,6 +37,10 @@ _loginctl () { [ARG]='--host -H --kill-who --property -p --signal -s' ) +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev ${OPTS[ARG]}; then case $prev in --signal|-s) @@ -106,4 +110,4 @@ _loginctl () { return 0 } -complete -F _loginctl loginctl +complete -o default -o bashdefault -F _loginctl loginctl diff --git shell-completion/bash/systemctl shell-completion/bash/systemctl index e1c8420..fa54e70 100644 --- shell-completion/bash/systemctl +++ shell-completion/bash/systemctl @@ -77,6 +77,10 @@ _systemctl () { [ARG]='--host -H --kill-who --property -p --signal -s --type -t --state --root' ) +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word --user ${COMP_WORDS[*]}; then mode=--user else @@
Re: [systemd-devel] [PATCH 11/11] Make redirections work with the bash command completions
From a cursory look, the bash-completion package deals with this issue in a more systematic way. See _init_completion() in /usr/share/bash-completion/bash_completion. Maybe it's worthwhile to (conditionally?) use that if possible. Ran On Fri, Jun 13, 2014 at 04:41:10PM +0200, Werner Fink wrote: --- shell-completion/bash/hostnamectl |6 +- shell-completion/bash/journalctl |6 +- shell-completion/bash/kernel-install | 13 - shell-completion/bash/localectl |6 +- shell-completion/bash/loginctl|6 +- shell-completion/bash/systemctl |6 +- shell-completion/bash/systemd-analyze |6 +- shell-completion/bash/systemd-coredumpctl |6 +- shell-completion/bash/systemd-run | 14 +- shell-completion/bash/timedatectl |6 +- shell-completion/bash/udevadm |6 +- 11 files changed, 70 insertions(+), 11 deletions(-) diff --git shell-completion/bash/hostnamectl shell-completion/bash/hostnamectl index 9c75da9..2e947f6 100644 --- shell-completion/bash/hostnamectl +++ shell-completion/bash/hostnamectl @@ -30,6 +30,10 @@ _hostnamectl() { local OPTS='-h --help --version --transient --static --pretty --no-ask-password -H --host' +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if [[ $cur = -* ]]; then COMPREPLY=( $(compgen -W '${OPTS[*]}' -- $cur) ) return 0 @@ -58,4 +62,4 @@ _hostnamectl() { return 0 } -complete -F _hostnamectl hostnamectl +complete -o default -o bashdefault -F _hostnamectl hostnamectl diff --git shell-completion/bash/journalctl shell-completion/bash/journalctl index e4b2f4a..50f83e0 100644 --- shell-completion/bash/journalctl +++ shell-completion/bash/journalctl @@ -49,6 +49,10 @@ _journalctl() { --verify-key' ) +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then case $prev in --boot|--this-boot|-b) @@ -111,4 +115,4 @@ _journalctl() { fi } -complete -F _journalctl journalctl +complete -o default -o bashdefault -F _journalctl journalctl diff --git shell-completion/bash/kernel-install shell-completion/bash/kernel-install index 7cd2494..33cf27c 100644 --- shell-completion/bash/kernel-install +++ shell-completion/bash/kernel-install @@ -18,11 +18,22 @@ # You should have received a copy of the GNU Lesser General Public License # along with systemd; If not, see http://www.gnu.org/licenses/. +__contains_word () { +local w word=$1; shift +for w in $@; do +[[ $w = $word ]] return +done +} + _kernel_install() { local comps local MACHINE_ID local cur=${COMP_WORDS[COMP_CWORD]} +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + case $COMP_CWORD in 1) comps=add remove @@ -47,4 +58,4 @@ _kernel_install() { return 0 } -complete -F _kernel_install kernel-install +complete -o default -o bashdefault -F _kernel_install kernel-install diff --git shell-completion/bash/localectl shell-completion/bash/localectl index c9e22af..3150f87 100644 --- shell-completion/bash/localectl +++ shell-completion/bash/localectl @@ -36,6 +36,10 @@ _localectl() { local OPTS='-h --help --version --no-convert --no-pager --no-ask-password -H --host' +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev $OPTS; then case $prev in --host|-H) @@ -89,4 +93,4 @@ _localectl() { return 0 } -complete -F _localectl localectl +complete -o default -o bashdefault -F _localectl localectl diff --git shell-completion/bash/loginctl shell-completion/bash/loginctl index e7adb93..9b137b4 100644 --- shell-completion/bash/loginctl +++ shell-completion/bash/loginctl @@ -37,6 +37,10 @@ _loginctl () { [ARG]='--host -H --kill-who --property -p --signal -s' ) +if __contains_word ${COMP_WORDS[*]:0:COMP_CWORD}; then +return 0 +fi + if __contains_word $prev ${OPTS[ARG]}; then case $prev in --signal|-s) @@ -106,4 +110,4 @@ _loginctl () { return 0 } -complete -F _loginctl loginctl +complete -o default -o bashdefault -F _loginctl loginctl diff --git shell-completion/bash/systemctl shell-completion/bash/systemctl index e1c8420..fa54e70