]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion: fix portablectl path completion with preceding params
authorLuca Boccassi <luca.boccassi@gmail.com>
Wed, 3 Dec 2025 22:23:23 +0000 (22:23 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 9 Dec 2025 05:39:07 +0000 (14:39 +0900)
The completion fails to complete to paths for verbs that need them when
a --param is the previous word, e.g.:

portablectl attach --runtime <tab>

fails to complete to paths

shell-completion/bash/portablectl

index 824510bbcae4538ebd09df4f98105f115205d53f..11294b9093e5a592a4492dc3af31c97967638003 100644 (file)
@@ -91,7 +91,7 @@ _portablectl() {
     elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
         comps=''
     elif __contains_word "$verb" ${VERBS[IMAGE]}; then
-        if [[ $n == 1 ]]; then
+        if [[ $n == 1 ]] || [[ "$prev" = -* ]] || __contains_word "${COMP_WORDS[COMP_CWORD-2]}" ${OPTS[ARG]}; then
             comps=$( compgen -A file -- "$cur" )
             compopt -o filenames
         else
@@ -101,10 +101,10 @@ _portablectl() {
         comps=$( compgen -A file -- "$cur" )
         compopt -o filenames
     elif __contains_word "$verb" ${VERBS[IMAGE_WITH_BOOL]}; then
-        if [[ $n == 1 ]]; then
+        if [[ $n == 1 ]] || [[ "$prev" = -* ]] || __contains_word "${COMP_WORDS[COMP_CWORD-2]}" ${OPTS[ARG]}; then
             comps=$( compgen -A file -- "$cur" )
             compopt -o filenames
-        elif [[ $n == 2 ]]; then
+        elif ! __contains_word "$prev" "yes" "no" && { [[ $n == 2 ]] || [[ "$prev" != -* ]]; }; then
             comps='yes no'
         else
             comps=''