diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-04-24 19:45:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-24 19:45:47 +0200 |
commit | 2d6888cc0d9351acacb110d1fa1e3c05e3e440fa (patch) | |
tree | 3588f1a1273a6f843c48860d703c5f3c44ec59d7 | |
parent | 1fa3ba909605c13761af69ae0ba1653292b6e730 (diff) | |
parent | 9521d5582b0e8ef9c48f23d957f9a4ddff80eafc (diff) | |
download | systemd-2d6888cc0d9351acacb110d1fa1e3c05e3e440fa.tar.gz |
Merge pull request #12376 from mrc0mmand/deal-with-backslashes-in-completion
bash-completion: properly autocomplete escaped unit names
-rw-r--r-- | shell-completion/bash/journalctl | 3 | ||||
-rw-r--r-- | shell-completion/bash/systemctl.in | 12 |
2 files changed, 12 insertions, 3 deletions
diff --git a/shell-completion/bash/journalctl b/shell-completion/bash/journalctl index 52ed2e3bcb..53ffaacdb5 100644 --- a/shell-completion/bash/journalctl +++ b/shell-completion/bash/journalctl @@ -86,6 +86,7 @@ _journalctl() { ;; --unit|-u) comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null) + compopt -o filenames ;; --user-unit) comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null) @@ -100,7 +101,7 @@ _journalctl() { return 0 ;; esac - COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) + COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") ) return 0 fi diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in index 8c86fed974..dfb2d4a4c9 100644 --- a/shell-completion/bash/systemctl.in +++ b/shell-completion/bash/systemctl.in @@ -114,11 +114,12 @@ __get_all_unit_files () { { __systemctl $1 list-unit-files "$2*"; } | { while re __get_machines() { local a b { machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; } | \ - { while read a b; do echo " $a"; done; } + { while read a b; do echo " $a"; done; } } _systemctl () { local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} + local cur_orig=$cur local i verb comps mode local -A OPTS=( @@ -221,6 +222,13 @@ _systemctl () { fi done + # When trying to match a unit name with certain special characters in its name (i.e + # foo\x2dbar:01) they get escaped by bash along the way, thus causing any possible + # match to fail. Let's unescape such characters in the verb we're trying to + # autocomplete to avoid this, however, use the original verb (cur_orig) + # during the final match (COMPREPLY) + cur="$(echo $cur | xargs echo)" + if [[ -z $verb ]]; then comps="${VERBS[*]}" @@ -306,7 +314,7 @@ _systemctl () { | { while read -r a b; do echo " $a"; done; } ) fi - COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") ) + COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur_orig") ) return 0 } |