]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion/zsh: complete hidden images when word starts with "." 31053/head
authorIvan Shapovalov <intelfx@intelfx.name>
Tue, 23 Jan 2024 00:10:49 +0000 (01:10 +0100)
committerIvan Shapovalov <intelfx@intelfx.name>
Tue, 23 Jan 2024 03:01:11 +0000 (04:01 +0100)
Show hidden images in the completion results, but only if the current
word starts with ".", such that
- `machinectl clone <Tab>` will only offer non-hidden images, but
- `machinectl clone .<Tab>` will offer both hidden and non-hidden images

shell-completion/zsh/_machinectl

index 54afa95bf6870fd7a5ed31a63389b77ef043f6b9..cb43721961e02783096208bd5e627d60850b6be4 100644 (file)
@@ -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] )) ||