diff options
author | Daniel Hahler <github@thequod.de> | 2016-08-13 16:41:22 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2016-08-13 10:41:22 -0400 |
commit | d551b8fcf75c32e34115a7ca638686e80be57657 (patch) | |
tree | 2c25ed6b31e8623d58f63249f2d95e24e602cff9 /shell-completion/zsh | |
parent | 9c5077fed42dc3cd2517a7ab816babef549dd079 (diff) |
zsh: _journalctl: improve support for handling mode args (#3952)
This only completes fields from `journalctl --user` in _journal_fields when `--user`
is used.
It also changes $_sys_service_mgr to include both `--system` and `--user`,
because `journalctl` behaves different from `systemctl` in this regard.
No attempt is made to filter out invalid combinations, e.g. when using both
`--directory` and `--system` (see https://github.com/systemd/systemd/issues/3949).
Diffstat (limited to 'shell-completion/zsh')
-rw-r--r-- | shell-completion/zsh/_journalctl | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/shell-completion/zsh/_journalctl b/shell-completion/zsh/_journalctl index 2271f7fa9c..e6549e863f 100644 --- a/shell-completion/zsh/_journalctl +++ b/shell-completion/zsh/_journalctl @@ -33,7 +33,7 @@ _journal_none() { _journal_fields() { local -a _fields cmd - cmd=("journalctl" "-F ${@[-1]}" "2>/dev/null" ) + cmd=("journalctl $_sys_service_mgr" "-F ${@[-1]}" "2>/dev/null" ) _fields=$(_call_program fields $cmd[@]) _fields=${_fields//'\'/'\\'} _fields=${_fields//':'/'\:'} @@ -51,8 +51,22 @@ _journal_boots() { "bootid:boot ids:compadd -a _bootid" } -local -a _modes; _modes=("--user" "--system") -local _sys_service_mgr=${${words:*_modes}[(R)(${(j.|.)_modes})]:---system} +# 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) +typeset -a _sys_service_mgr +local w 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))]}) + fi + fi +done _arguments -s \ {-h,--help}'[Show this help]' \ '--version[Show package version]' \ |