diff options
author | Eric Cook <llua@gmx.com> | 2015-06-17 07:41:24 -0400 |
---|---|---|
committer | Eric Cook <llua@gmx.com> | 2015-06-17 07:41:24 -0400 |
commit | b0fe29ff9e04d02d939ffca0b942cfb2a3494171 (patch) | |
tree | 1b26bff57600ae73c521941428b7f1edb44e822b | |
parent | c986cc70002cf8f28e6ea1e63da46a8124a0882c (diff) |
zsh-completion: _loginctl - general bug fixes
1) the iterator `fun' has an local scope. after running the completer,
it will no longer be defined.
2) use _describe instead of calling compadd. Using compadd without
calling _description or something similar before, restricts the
user's ability to customize what is presented to them.
zstyle ':completion:*' format 'Completing %d'
- now displays an header showing what is being completed.
zstyle ':completion::complete:loginctl-*::users' users user1 user2
- allows the user to manually specify which users is offered
zstyle :completion::complete:loginctl-kill-user:\* \
ignored-patterns '(100<0-4>|user1)'
- selectively ignore some users when completing loginctl kill-user
<tab>
Sessions, UIDs now have descriptions when selecting them.
3) removed the call to _loginctl_all_seats in _loginctl_attach(), since
_loginctl_seats calls it a second time, right before adding matches.
There isn't a noticeable difference doing this.
-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]:*]%%:*}}" |