From d551b8fcf75c32e34115a7ca638686e80be57657 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 Aug 2016 16:41:22 +0200 Subject: 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). --- shell-completion/zsh/_journalctl | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'shell-completion/zsh') 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]' \ -- cgit v1.2.3-54-g00ecf From e09d0d46c297068d9d742d8a00c2c52e2d95a0c1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 Aug 2016 16:42:55 +0200 Subject: zsh: _systemctl: do not attempt to use "--system" by default (#3951) In 68c4f6d the following was added: local -a _modes; _modes=("--user" "--system") local _sys_service_mgr=${${words:*_modes}[(R)(${(j.|.)_modes})]:---system} With the following comment: > If neither are on the line, --system is set; for system services to be > completed. But it does not work as documented: % _modes=(--user --system) % words=() % echo ${${words:*_modes}[(R)(${(j.|.)_modes})]:---system} However, it should not use `--system` in that case anyway, so this patch removes the part that should cause a default to be used and adds some comments. --- shell-completion/zsh/_systemctl.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'shell-completion/zsh') diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index 69f643303d..b525286932 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -351,8 +351,10 @@ _job_modes() { _values -s , "${_modes[@]}" } +# Build arguments for "systemctl" to be used in completion. local -a _modes; _modes=("--user" "--system") -local _sys_service_mgr=${${words:*_modes}[(R)(${(j.|.)_modes})]:---system} +# Use the last mode (they are exclusive and the last one is used). +local _sys_service_mgr=${${words:*_modes}[(R)(${(j.|.)_modes})]} _arguments -s \ {-h,--help}'[Show help]' \ '--version[Show package version]' \ -- cgit v1.2.3-54-g00ecf From ba89f80620d619867b4838973785d529c5a959f6 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 16 Aug 2016 18:42:41 +0200 Subject: zsh: _journalctl: do not complete exclusive modes (#3957) After `journalctl -D /var/log/journal` "--directory", "--file", "--machine" and "--root" should not be available for completion, because they are exclusive. But multiple `--file` arguments are allowed. --- shell-completion/zsh/_journalctl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'shell-completion/zsh') diff --git a/shell-completion/zsh/_journalctl b/shell-completion/zsh/_journalctl index e6549e863f..610788dcce 100644 --- a/shell-completion/zsh/_journalctl +++ b/shell-completion/zsh/_journalctl @@ -96,10 +96,10 @@ _arguments -s \ {-F,--field=}'[List all values a certain field takes]:Fields:_list_fields' \ '--system[Show system and kernel messages]' \ '--user[Show messages from user services]' \ - {-M+,--machine=}'[Operate on local container]:machines:_sd_machines' \ - {-D+,--directory=}'[Show journal files from directory]:directories:_directories' \ - '--file=[Operate on specified journal files]:file:_files' \ - '--root=[Operate on catalog hierarchy under specified directory]:directories:_directories' \ + '(--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' \ '--new-id128[Generate a new 128 Bit ID]' \ '--header[Show journal header information]' \ '--disk-usage[Show total disk usage]' \ -- cgit v1.2.3-54-g00ecf From b2fe35fe58f5229c0a265c86877b5d08114a2867 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 16 Aug 2016 18:47:39 +0200 Subject: zsh: _journalctl: also handle --root arg and --key=value style (#3956) This will now also handle `journalctl --directory=/var/log/journal` properly. --- shell-completion/zsh/_journalctl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'shell-completion/zsh') diff --git a/shell-completion/zsh/_journalctl b/shell-completion/zsh/_journalctl index 610788dcce..ef67fcf2a0 100644 --- a/shell-completion/zsh/_journalctl +++ b/shell-completion/zsh/_journalctl @@ -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 -- cgit v1.2.3-54-g00ecf From c0f9116d6cd795edd9d4df8d27a87a7232d3e675 Mon Sep 17 00:00:00 2001 From: Davide Cavalca Date: Wed, 14 Sep 2016 13:38:53 -0700 Subject: shell-completion: add --wait to systemd-run completions (#4140) --- shell-completion/bash/systemd-run | 3 ++- shell-completion/zsh/_systemd-run | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'shell-completion/zsh') diff --git a/shell-completion/bash/systemd-run b/shell-completion/bash/systemd-run index 022331e6a9..4116ba7eca 100644 --- a/shell-completion/bash/systemd-run +++ b/shell-completion/bash/systemd-run @@ -36,7 +36,8 @@ _systemd_run() { -r --remain-after-exit --send-sighup -H --host -M --machine --service-type --on-active --on-boot --on-startup --on-unit-active --on-unit-inactive --on-calendar --timer-property -t --pty -q --quiet --no-block - --uid --gid --nice --setenv -p --property --no-ask-password' + --uid --gid --nice --setenv -p --property --no-ask-password + --wait' local mode=--system local i diff --git a/shell-completion/zsh/_systemd-run b/shell-completion/zsh/_systemd-run index 6362b97766..da9f73a6d0 100644 --- a/shell-completion/zsh/_systemd-run +++ b/shell-completion/zsh/_systemd-run @@ -57,4 +57,5 @@ _arguments \ '--on-unit-inactive=[Run after SEC seconds from the last deactivation]:SEC' \ '--on-calendar=[Realtime timer]:SPEC' \ '--timer-property=[Set timer unit property]:NAME=VALUE' \ + '--wait=[Wait until service stopped again]' \ '*::command:_command' -- cgit v1.2.3-54-g00ecf From 6c9414a700a040be1d3160bd2336baac58a1da3e Mon Sep 17 00:00:00 2001 From: llua Date: Mon, 17 Oct 2016 08:35:26 -0400 Subject: zsh-completion: fix for #4318 (#4394) Escape unit names for the eval call in _call_program The value of the Id property is transformed back into a unit name usable by systemctl. system-systemd\x5cx2dcryptsetup.slice -> system-systemd\x2dcryptsetup.slice Also filter units by property via parameter expansion, not a for loop --- shell-completion/zsh/_systemctl.in | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'shell-completion/zsh') diff --git a/shell-completion/zsh/_systemctl.in b/shell-completion/zsh/_systemctl.in index b525286932..03a1c930b0 100644 --- a/shell-completion/zsh/_systemctl.in +++ b/shell-completion/zsh/_systemctl.in @@ -123,15 +123,11 @@ _systemctl_really_all_units() } _filter_units_by_property() { - local property=$1 value=$2 ; shift ; shift - local -a units ; units=($*) - local props - for props in ${(ps:\n\n:)"$(_call_program units "$service $_sys_service_mgr show --no-pager --property="Id,$property" -- ${units} 2>/dev/null")"}; do - props=(${(f)props}) - if [[ "${props[2]}" = "$property=$value" ]]; then - echo -E - " ${props[1]#Id=}" - fi - done + local property=$1 value=$2; shift 2 + local -a units; units=("${(q-)@}") + local -A props + props=(${(f)"$(_call_program units "$service $_sys_service_mgr show --no-pager --property=\"Id,$property\" -- ${units} 2>/dev/null")"}) + echo -E - "${(@g:o:)${(k@)props[(Re)$property=$value]}#Id=}" } _systemctl_get_template_names() { echo -E - ${^${(M)${(f)"$(__systemctl list-unit-files)"}##*@.[^[:space:]]##}%%@.*}\@ } -- cgit v1.2.3-54-g00ecf