From: Ivan Shapovalov Date: Tue, 23 Jan 2024 00:10:49 +0000 (+0100) Subject: shell-completion/zsh: complete hidden images when word starts with "." X-Git-Tag: v256-rc1~1073^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F31053%2Fhead;p=thirdparty%2Fsystemd.git shell-completion/zsh: complete hidden images when word starts with "." Show hidden images in the completion results, but only if the current word starts with ".", such that - `machinectl clone ` will only offer non-hidden images, but - `machinectl clone .` will offer both hidden and non-hidden images --- diff --git a/shell-completion/zsh/_machinectl b/shell-completion/zsh/_machinectl index 54afa95bf68..cb43721961e 100644 --- a/shell-completion/zsh/_machinectl +++ b/shell-completion/zsh/_machinectl @@ -3,7 +3,12 @@ (( $+functions[__machinectl_get_images] )) || __machinectl_get_images () { - machinectl --no-legend list-images | {while read -r a b; do echo $a; done;} + local -a flags + if [[ $PREFIX == .* ]]; then flags=( --all ); fi + machinectl --no-legend list-images $flags | {while read -r a b; do + # escape : and \; do not interpret existing escape sequences + printf -- "%s\n" ${a//(#b)(\\|:)/\\$match} + done;} } (( $+functions[_machinectl_images] )) ||