]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - shell-completion/zsh/_journalctl
zsh-completion: _journalctl fixes (#5165)
[thirdparty/systemd.git] / shell-completion / zsh / _journalctl
index 610788dcce9192b5f8597c24403aa7a4f52693c8..4a78a2e9460127ffbddf6ee5675351ec3400bc56 100644 (file)
@@ -54,16 +54,25 @@ _journal_boots() {
 # Build arguments for "journalctl" to be used in completion.
 # Use both --user and --system modes, they are not exclusive.
 local -a _modes; _modes=(--user --system)
-local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine)
+local -a _modes_with_arg; _modes_with_arg=(--directory -D --file -M --machine --root)
 typeset -a _sys_service_mgr
-local w i=0 n=$#words
+local w k v i=0 n=$#words
 while (( i++ < n )); do
     w=$words[$i]
     if (( $_modes[(I)$w] )); then
         _sys_service_mgr+=($w)
     else
-        if (( ${_modes_with_arg[(I)$w]} )); then
-            _sys_service_mgr+=($w ${words[((++i))]})
+        # Handle options with arguments. "--key=value" and "--key value".
+        k=${w%%=*}
+        if (( ${_modes_with_arg[(I)$k]} )); then
+            v=${w#*=}
+            if [[ "$k" != "$w" ]]; then
+                # "--key=value" style.
+                _sys_service_mgr+=($w)
+            else
+                # "--key value" style.
+                _sys_service_mgr+=($w ${words[((++i))]})
+            fi
         fi
     fi
 done
@@ -98,8 +107,8 @@ _arguments -s \
     '--user[Show messages from user services]' \
     '(--directory -D -M --machine --root --file)'{-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \
     '(--directory -D -M --machine --root --file)'{-D+,--directory=}'[Show journal files from directory]:directories:_directories' \
-    '(--directory -D -M --machine --root --file)''--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \
-    '(--directory -D -M --machine --root)--file=[Operate on specified journal files]:file:_files' \
+    '(--directory -D -M --machine --root --file)--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \
+    '(--directory -D -M --machine --root)*--file=[Operate on specified journal files]:file:_files' \
     '--new-id128[Generate a new 128 Bit ID]' \
     '--header[Show journal header information]' \
     '--disk-usage[Show total disk usage]' \