[systemd-devel] [PATCH] bash-completion: --property support

Dave Reisner d at falconindy.com
Tue Apr 16 10:57:47 PDT 2013


On Tue, Apr 16, 2013 at 01:48:14PM -0400, Zbigniew Jędrzejewski-Szmek wrote:
> ---
> It turns out that simply fetching the list is fast enough.
> At least on my relatively beefy machine. And this approach
> is quite easy. So I think we can do that.
>
> Zbyszek
>
>  shell-completion/bash/systemctl | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/shell-completion/bash/systemctl b/shell-completion/bash/systemctl
> index f24a145..2c004d9 100644
> --- a/shell-completion/bash/systemctl
> +++ b/shell-completion/bash/systemctl
> @@ -22,6 +22,17 @@ __systemctl() {
>          systemctl $mode --full --no-legend "$@"
>  }
>
> +__systemd_properties() {
> +        local mode=$1; shift 1

The shift seems superfluous here -- you never reference any positional
params in this function.

> +        { __systemctl $mode show;
> +         systemd --dump-configuration-items; } |
> +        while read -r line; do
> +            if [[ "$line" =~ .*= ]]; then
> +                echo ${line%%=*}
> +            fi

I'd skip the regex and just split in the while loop:

  while IFS='=' read -r key value; do
    [[ $value ]] && echo "$key"
  done

> +        done
> +}
> +
>  __contains_word () {
>          local word=$1; shift
>          for w in $*; do [[ $w = $word ]] && return 0; done
> @@ -67,6 +78,12 @@ _systemctl () {
>                        [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
>          )
>
> +        if __contains_word "--user" ${COMP_WORDS[*]}; then
> +            mode=--user
> +        else
> +            mode=--system
> +        fi
> +
>          if __contains_word "$prev" ${OPTS[ARG]}; then
>                  case $prev in
>                          --signal|-s)
> @@ -89,7 +106,7 @@ _systemctl () {
>                                  comps=$(compgen -A hostname)
>                          ;;
>                          --property|-p)
> -                                comps=''
> +                                comps=$(__systemd_properties $mode)
>                          ;;
>                  esac
>                  COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
> @@ -101,12 +118,6 @@ _systemctl () {
>                  return 0
>          fi
>
> -        if __contains_word "--user" ${COMP_WORDS[*]}; then
> -            mode=--user
> -        else
> -            mode=--system
> -        fi
> -
>          local -A VERBS=(
>                  [ALL_UNITS]='is-active is-failed is-enabled status show mask preset'
>              [ENABLED_UNITS]='disable'
> --
> 1.8.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