diff options
author | Daniel Mack <github@zonque.org> | 2015-06-17 21:37:46 +0200 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2015-06-17 21:37:46 +0200 |
commit | d5df0d950f8bc91633800476947b5f856a10fc08 (patch) | |
tree | 1950cd7cd34f532421cd97dcddfa95398f636bf4 | |
parent | 7391cb5d581c4d48dec689686fd9514fdb7d4888 (diff) | |
parent | b0fe29ff9e04d02d939ffca0b942cfb2a3494171 (diff) |
Merge pull request #248 from llua/zsh-completion
zsh-completion: _loginctl - general bug fixes
-rw-r--r-- | shell-completion/zsh/_loginctl | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/shell-completion/zsh/_loginctl b/shell-completion/zsh/_loginctl index bd33b66fae..1e2a4db2a0 100644 --- a/shell-completion/zsh/_loginctl +++ b/shell-completion/zsh/_loginctl @@ -1,15 +1,43 @@ #compdef loginctl -_loginctl_all_sessions(){_sys_all_sessions=($(loginctl --no-legend list-sessions | { while read a b; do echo " $a"; done; }) )} -_loginctl_all_users() {_sys_all_users=( $(loginctl --no-legend list-users | { while read a b; do echo " $a"; done; }) )} -_loginctl_all_seats() {_sys_all_seats=( $(loginctl --no-legend list-seats | { while read a b; do echo " $a"; done; }) )} +_loginctl_all_sessions() { + local session description + loginctl --no-legend list-sessions | while read -r session description; do + _sys_all_sessions+=( "$session" ) + _sys_all_sessions_descr+=( "${session}:$description" ) + done +} + +_loginctl_all_users() { + local uid description + loginctl --no-legend list-users | while read -r uid description; do + _sys_all_users+=( "$uid" ) + _sys_all_users_descr+=( "${uid}:$description" ) + done +} +_loginctl_all_seats() { + local seat description + loginctl --no-legend list-seats | while read -r seat description; do + _sys_all_seats+=( "$seat" ) + _sys_all_seats_descr+=( "${seat}:$description" ) + done +} + +local fun # Completion functions for SESSIONS for fun in session-status show-session activate lock-session unlock-session terminate-session kill-session ; do (( $+functions[_loginctl_$fun] )) || _loginctl_$fun() { + local -a _sys_all_sessions{,_descr} + _loginctl_all_sessions - compadd "$@" -a - _sys_all_sessions + for _ignore in $words[2,-1]; do + _sys_all_sessions[(i)$_ignore]=() + _sys_all_sessions_descr[(i)$_ignore:*]=() + done + + _describe -t systemd-sessions session _sys_all_sessions_descr _sys_all_sessions "$@" } done @@ -17,16 +45,34 @@ done for fun in user-status show-user enable-linger disable-linger terminate-user kill-user ; do (( $+functions[_loginctl_$fun] )) || _loginctl_$fun() { - _loginctl_all_users - compadd "$@" -a - _sys_all_users + local -a _sys_all_users{,_descr} + zstyle -a ":completion:${curcontext}:users" users _sys_all_users + + if ! (( $#_sys_all_users )); then + _loginctl_all_users + fi + + for _ignore in $words[2,-1]; do + _sys_all_users[(i)$_ignore]=() + _sys_all_users_descr[(i)$_ignore:*]=() + done + # using the common tag `users' here, not rolling our own `systemd-users' tag + _describe -t users user ${_sys_all_users_descr:+_sys_all_users_descr} _sys_all_users "$@" } done # Completion functions for SEATS (( $+functions[_loginctl_seats] )) || _loginctl_seats() { + local -a _sys_all_seats{,_descr} + _loginctl_all_seats - compadd "$@" -a - _sys_all_seats + for _ignore in $words[2,-1]; do + _sys_all_seats[(i)$_ignore]=() + _sys_all_seats_descr[(i)$_ignore:*]=() + done + + _describe -t systemd-seats seat _sys_all_seats_descr _sys_all_seats "$@" } for fun in seat-status show-seat terminate-seat ; do (( $+functions[_loginctl_$fun] )) || _loginctl_$fun() @@ -36,8 +82,6 @@ done # Completion functions for ATTACH (( $+functions[_loginctl_attach] )) || _loginctl_attach() { - _loginctl_all_seats - _arguments -w -C -S -s \ ':seat:_loginctl_seats' \ '*:device:_files' @@ -78,7 +122,7 @@ done if (( CURRENT == 1 )); then _describe -t commands 'loginctl command' _loginctl_cmds || compadd "$@" else - local curcontext="$curcontext" + local curcontext="$curcontext" _ignore cmd="${${_loginctl_cmds[(r)$words[1]:*]%%:*}}" |