[systemd-devel] [PATCH] shell-completion: prevent mangling unit names
Units with literal hex '\xFF' in their names has to be read and printed properly. dev-disk-byx2dlabel-root.device != dev-disk-by\x2dlabel-root.device --- shell-completion/zsh/_systemctl.in | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index d364d17..e681ec6 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -100,7 +100,7 @@ _systemctl_all_units() if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) ! _retrieve_cache SYS_ALL_UNITS; then -_sys_all_units=( $(__systemctl list-units --all | { while read a b; do echo $a; done; }) ) +_sys_all_units=( $(__systemctl list-units --all | { while read -r a b; do echo -E - $a; done; }) ) _store_cache SYS_ALL_UNITS _sys_all_units fi } @@ -113,7 +113,7 @@ _systemctl_really_all_units() if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) ! _retrieve_cache SYS_REALLY_ALL_UNITS; then -all_unit_files=( $(__systemctl list-unit-files | { while read a b; do echo $a; done; }) ) +all_unit_files=( $(__systemctl list-unit-files | { while read -r a b; do echo -E - $a; done; }) ) _systemctl_all_units really_all_units=($_sys_all_units $all_unit_files) _sys_really_all_units=(${(u)really_all_units}) @@ -138,12 +138,12 @@ _filter_units_by_property() { done } -_systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read a b; do echo $a; done; }) )} -_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all| { while read a b c d; do [[ $c == inactive || $c == failed ]] echo $a; done; }) )} -_systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read a b; do echo $a; done; }) )} -_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == enabled ]] echo $a; done; }) )} -_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read a b; do [[ $b == disabled ]] echo $a; done; }) )} -_systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read a b; do [[ $b == masked ]] echo $a; done; }) )} +_systemctl_active_units() {_sys_active_units=( $(__systemctl list-units | { while read -r a b; do echo -E - $a; done; }) )} +_systemctl_inactive_units(){_sys_inactive_units=($(__systemctl list-units --all| { while read -r a b c d; do [[ $c == inactive || $c == failed ]] echo -E - $a; done; }) )} +_systemctl_failed_units() {_sys_failed_units=( $(__systemctl list-units --failed | { while read -r a b; do echo -E - $a; done; }) )} +_systemctl_enabled_units() {_sys_enabled_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == enabled ]] echo -E - $a; done; }) )} +_systemctl_disabled_units(){_sys_disabled_units=($(__systemctl list-unit-files | { while read -r a b; do [[ $b == disabled ]] echo -E - $a; done; }) )} +_systemctl_masked_units() {_sys_masked_units=( $(__systemctl list-unit-files | { while read -r a b; do [[ $b == masked ]] echo -E - $a; done; }) )} # Completion functions for ALL_UNITS for fun in is-active is-failed is-enabled status show cat mask preset help list-dependencies ; do @@ -219,8 +219,8 @@ for fun in restart reload-or-restart ; do { _systemctl_all_units compadd $@ - $( _filter_units_by_property CanStart yes \ - ${_sys_all_units[*]} | while read line; do \ - [[ $line =~ \.device$ ]] || echo $line; \ + ${_sys_all_units[*]} | while read -r line; do \ + [[ $line =~ \.device$ ]] || echo -E - $line; \ done ) } done -- 2.0.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH] shell-completion: prevent mangling unit names
On Sat, Jul 26, 2014 at 11:15:52AM -0400, Eric Cook wrote: Units with literal hex '\xFF' in their names has to be read and printed properly. dev-disk-byx2dlabel-root.device != dev-disk-by\x2dlabel-root.device Applied. Any chance you could do the equivalent for bash? Zbyszek --- shell-completion/zsh/_systemctl.in | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] shell-completion: prevent mangling unit names (bash)
This looks seems like it should work. I would appreciate it if you could trail run it. My use of bash is limited and knowledge of it's completion system even more so. --- shell-completion/bash/systemctl.in | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in index c5950cc..113694f 100644 --- a/shell-completion/bash/systemctl.in +++ b/shell-completion/bash/systemctl.in @@ -46,25 +46,25 @@ __filter_units_by_property () { (__systemctl $mode show --property $property -- ${units[@]}) for ((i=0; $i ${#units[*]}; i++)); do if [[ ${props[i]} = $property=$value ]]; then -echo ${units[i]} +printf '%q\n' ${units[i]} fi done } __get_all_units () { __systemctl $1 list-units --all \ -| { while read -r a b; do echo $a; done; }; } +| { while read -r a b; do printf '%q\n' $a; done; }; } __get_active_units () { __systemctl $1 list-units \ -| { while read -r a b; do echo $a; done; }; } +| { while read -r a b; do printf '%q\n' $a; done; }; } __get_startable_units () { __systemctl $1 list-units --all -t service,timer,socket,mount,automount,path,snapshot,swap \ -| { while read -r a b c d; do [[ $c == inactive || $c == failed ]] echo $a; done; }; } +| { while read -r a b c d; do [[ $c == inactive || $c == failed ]] printf '%q\n' $a; done; }; } __get_failed_units () { __systemctl $1 list-units \ -| { while read -r a b c d; do [[ $c == failed ]] echo $a; done; }; } +| { while read -r a b c d; do [[ $c == failed ]] printf '%q\n' $a; done; }; } __get_enabled_units () { __systemctl $1 list-unit-files \ -| { while read -r a b c ; do [[ $b == enabled ]] echo $a; done; }; } +| { while read -r a b c ; do [[ $b == enabled ]] printf '%q\n' $a; done; }; } __get_disabled_units () { __systemctl $1 list-unit-files \ -| { while read -r a b c ; do [[ $b == disabled ]] echo $a; done; }; } +| { while read -r a b c ; do [[ $b == disabled ]] printf '%q\n' $a; done; }; } __get_masked_units () { __systemctl $1 list-unit-files \ -| { while read -r a b c ; do [[ $b == masked ]] echo $a; done; }; } +| { while read -r a b c ; do [[ $b == masked ]] printf '%q\n' $a; done; }; } _systemctl () { local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} -- 2.0.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH] shell-completion: prevent mangling unit names (bash)
On Sat, Jul 26, 2014 at 05:24:11PM -0400, Eric Cook wrote: This looks seems like it should work. I would appreciate it if you could trail run it. My use of bash is limited and knowledge of it's completion system even more so. --- Unfortunately it works only partially. It seems that completions are generated properly, but bash doesn't seem to be able to continue after a backslash, so one has to copy in the remaining part by hand. Zbyszek shell-completion/bash/systemctl.in | 16 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in index c5950cc..113694f 100644 --- a/shell-completion/bash/systemctl.in +++ b/shell-completion/bash/systemctl.in @@ -46,25 +46,25 @@ __filter_units_by_property () { (__systemctl $mode show --property $property -- ${units[@]}) for ((i=0; $i ${#units[*]}; i++)); do if [[ ${props[i]} = $property=$value ]]; then -echo ${units[i]} +printf '%q\n' ${units[i]} fi done } __get_all_units () { __systemctl $1 list-units --all \ -| { while read -r a b; do echo $a; done; }; } +| { while read -r a b; do printf '%q\n' $a; done; }; } __get_active_units () { __systemctl $1 list-units \ -| { while read -r a b; do echo $a; done; }; } +| { while read -r a b; do printf '%q\n' $a; done; }; } __get_startable_units () { __systemctl $1 list-units --all -t service,timer,socket,mount,automount,path,snapshot,swap \ -| { while read -r a b c d; do [[ $c == inactive || $c == failed ]] echo $a; done; }; } +| { while read -r a b c d; do [[ $c == inactive || $c == failed ]] printf '%q\n' $a; done; }; } __get_failed_units () { __systemctl $1 list-units \ -| { while read -r a b c d; do [[ $c == failed ]] echo $a; done; }; } +| { while read -r a b c d; do [[ $c == failed ]] printf '%q\n' $a; done; }; } __get_enabled_units () { __systemctl $1 list-unit-files \ -| { while read -r a b c ; do [[ $b == enabled ]] echo $a; done; }; } +| { while read -r a b c ; do [[ $b == enabled ]] printf '%q\n' $a; done; }; } __get_disabled_units () { __systemctl $1 list-unit-files \ -| { while read -r a b c ; do [[ $b == disabled ]] echo $a; done; }; } +| { while read -r a b c ; do [[ $b == disabled ]] printf '%q\n' $a; done; }; } __get_masked_units () { __systemctl $1 list-unit-files \ -| { while read -r a b c ; do [[ $b == masked ]] echo $a; done; }; } +| { while read -r a b c ; do [[ $b == masked ]] printf '%q\n' $a; done; }; } _systemctl () { local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} -- 2.0.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH] shell-completion: prevent mangling unit names (bash)
On 07/26/2014 07:52 PM, Zbigniew Jędrzejewski-Szmek wrote: Unfortunately it works only partially. It seems that completions are generated properly, but bash doesn't seem to be able to continue after a backslash, so one has to copy in the remaining part by hand. Zbyszek Hm... (I think)Once we add our own `\' to escape the unit name, the compgen tests fails to match units. (lines 116, 121 and 225) That can be avoided in a hack-ish way by escaping `cur' with `cur=${cur//\\/}' but when completing the unit like 'dev-tab (with the quote) the additional `\' are still inserted. So... i'll look more into it, i may be over thinking it. :D ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel