[systemd-devel] [PATCH 11/11] Make redirections work with the bash command completions
Ran Benita
ran234 at gmail.com
Fri Jun 13 09:09:50 PDT 2014
>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 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
> @@ -223,4 +227,4 @@ _systemctl () {
> return 0
> }
>
> -complete -F _systemctl systemctl
> +complete -o default -o bashdefault -F _systemctl systemctl
> diff --git shell-completion/bash/systemd-analyze shell-completion/bash/systemd-analyze
> index 5575beb..2d195aa 100644
> --- shell-completion/bash/systemd-analyze
> +++ shell-completion/bash/systemd-analyze
> @@ -46,6 +46,10 @@ _systemd_analyze() {
> [LOG_LEVEL]='set-log-level'
> )
>
> + if __contains_word ">" ${COMP_WORDS[*]:0:COMP_CWORD}; then
> + return 0
> + fi
> +
> _init_completion || return
>
> for ((i=0; i < COMP_CWORD; i++)); do
> @@ -105,4 +109,4 @@ _systemd_analyze() {
> return 0
> }
>
> -complete -F _systemd_analyze systemd-analyze
> +complete -o default -o bashdefault -F _systemd_analyze systemd-analyze
> diff --git shell-completion/bash/systemd-coredumpctl shell-completion/bash/systemd-coredumpctl
> index 805e848..8f29651 100644
> --- shell-completion/bash/systemd-coredumpctl
> +++ shell-completion/bash/systemd-coredumpctl
> @@ -44,6 +44,10 @@ _coredumpctl() {
> [DUMP]='dump gdb'
> )
>
> + if __contains_word ">" ${COMP_WORDS[*]:0:COMP_CWORD}; then
> + return 0
> + fi
> +
> if __contains_word "$prev" '--output -o'; then
> comps=$( compgen -A file -- "$cur" )
> compopt -o filenames
> @@ -82,4 +86,4 @@ _coredumpctl() {
> return 0
> }
>
> -complete -F _coredumpctl systemd-coredumpctl
> +complete -o default -o bashdefault -F _coredumpctl systemd-coredumpctl
> diff --git shell-completion/bash/systemd-run shell-completion/bash/systemd-run
> index 712655c..e547e95 100644
> --- shell-completion/bash/systemd-run
> +++ shell-completion/bash/systemd-run
> @@ -17,6 +17,13 @@
> # 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
> +}
> +
> __systemctl() {
> local mode=$1; shift 1
> systemctl $mode --full --no-legend "$@"
> @@ -38,6 +45,11 @@ _systemd_run() {
>
> local mode=--system
> local i
> +
> + if __contains_word ">" ${COMP_WORDS[*]:0:COMP_CWORD}; then
> + return 0
> + fi
> +
> for (( i=1; i <= COMP_CWORD; i++ )); do
> if [[ ${COMP_WORDS[i]} != -* ]]; then
> local root_command=${COMP_WORDS[i]}
> @@ -98,4 +110,4 @@ _systemd_run() {
> return 0
> }
>
> -complete -F _systemd_run systemd-run
> +complete -o default -o bashdefault -F _systemd_run systemd-run
> diff --git shell-completion/bash/timedatectl shell-completion/bash/timedatectl
> index 1a0acc6..d0ca51d 100644
> --- shell-completion/bash/timedatectl
> +++ shell-completion/bash/timedatectl
> @@ -30,6 +30,10 @@ _timedatectl() {
> local OPTS='-h --help --version --adjust-system-clock --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)
> @@ -73,4 +77,4 @@ _timedatectl() {
> return 0
> }
>
> -complete -F _timedatectl timedatectl
> +complete -o default -o bashdefault -F _timedatectl timedatectl
> diff --git shell-completion/bash/udevadm shell-completion/bash/udevadm
> index b828b8d..e7cf29f 100644
> --- shell-completion/bash/udevadm
> +++ shell-completion/bash/udevadm
> @@ -36,6 +36,10 @@ _udevadm() {
>
> local verbs=(info trigger settle control monitor hwdb test-builtin test)
>
> + if __contains_word ">" ${COMP_WORDS[*]:0:COMP_CWORD}; then
> + return 0
> + fi
> +
> for ((i=0; i < COMP_CWORD; i++)); do
> if __contains_word "${COMP_WORDS[i]}" "${verbs[@]}" &&
> ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
> @@ -94,4 +98,4 @@ _udevadm() {
> return 0
> }
>
> -complete -F _udevadm udevadm
> +complete -o default -o bashdefault -F _udevadm udevadm
> --
> 1.7.9.2
>
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
More information about the systemd-devel
mailing list