From: Anthony R Fletcher <arif@mail.nih.gov>
To: <zsh-users@zsh.org>
Subject: Re: systemctl completion
Date: Wed, 17 Aug 2011 11:09:45 -0400 [thread overview]
Message-ID: <20110817150945.GA25599@cosy.cit.nih.gov> (raw)
In-Reply-To: <20110729121054.GA25893@cosy.cit.nih.gov>
[-- Attachment #1: Type: text/plain, Size: 510 bytes --]
Here is my first attempt for systemctl completion. It mostly works for
me and hopefully it'll work for others. Suggestions welcome.
Anthony
On 29 Jul 2011 at 08:10:54, Anthony R Fletcher wrote:
> Does anyone have a completion script for systemd's systemctl?
>
> Anthony.
>
--
Anthony R Fletcher
Room 2033, Building 12A, http://dcb.cit.nih.gov/~arif
National Institutes of Health, arif@mail.nih.gov
12A South Drive, Bethesda, Phone: (+1) 301 402 1741.
MD 20892-5624, USA.
[-- Attachment #2: _systemctl --]
[-- Type: text/plain, Size: 3502 bytes --]
#compdef systemctl
# Completion for systemd's systemctl
# Version 1.0 ARF 3 August 2011
# list the unit completions.
_systemd_units(){
local -a units
local expl
units=(${(f)"$( systemctl --full list-units | sed -e 's/ .*//' )"})
_wanted keys expl 'units' compadd "$units[@]"
}
# list the job completions.
_systemd_jobs(){
local -a jobs
local expl
jobs=(${(f)"$( systemctl --full list-jobs | sed -e 's/ .*//' )"})
_wanted keys expl 'jobs' compadd "$jobs[@]"
}
# list the snapshot completions.
_systemd_snapshots(){
local -a ss
local expl
ss=(${(f)"$(
systemctl dump | sed -n -e 's/^-> Unit \(.*\.snapshot\):/\1/p'
)"})
_wanted keys expl 'snapshots' compadd "$ss[@]"
}
_systemctl(){
local -a _systemctl_cmds
# Determine the sub commands
#$(systemctl --help | sed -n -e 's/^ \([a-z]\)/\1/p' | sed -e 's/ .*//')
_systemctl_cmds=(
list-units start stop reload restart try-restart reload-or-
restart reload-or-try-restart isolate kill is-active status show
reset-failed enable disable is-enabled load list-jobs cancel
monitor dump dot snapshot delete daemon-reload daemon-reexec show-
environment set-environment unset-environment default rescue
emergency halt poweroff reboot kexec exit
)
local curcontext="$curcontext" state line expl
typeset -A opt_args
# Initial flags
_arguments -A '-*' \
'--help[Show help]' \
'--version[Show package version]' \
'(-a,--all)'{-a,--all}'[Show all units/properties, including dead/empty ones]' \
'--full[Dont ellipsize unit names on output]' \
'--failed[Show only failed units]' \
'--fail[When queueing a new job, fail if conflicting jobs are pending]' \
'--ignore-dependencies[ignore dependencies]' \
'(-p,--privileged)'{-p,--privileged}'[Acquire privileges before execution]' \
'(-q,--quiet)'{-q,--quiet}'[Suppress output]' \
'--no-block[Do not wait until operation finished]' \
'--no-wall[Dont send wall message before halt/power-off/reboot]' \
'--no-reload[dont reload daemon configuration]' \
'--no-pager[Do use pager]' \
'--no-ask-password[Do not ask for system passwords]' \
'--order[When generating graph for dot, show only order]' \
'--require[When generating graph for dot, show only requirement]' \
'--system[Connect to system manager]' \
'--user[Connect to user service manager]' \
'--global[Enable/disable unit files globally]' \
'(-f,--force)'{-f,--force}'[When enabling unit files, override existing symlinks. When shutting down, execute action immediately]' \
'--defaults[When disabling unit files, remove default symlinks only]' \
'*::command:->subcmd' && return 0
# Complete subcommands.
if (( CURRENT == 1 )); then
_describe -t commands "command" _systemctl_cmds
return
fi
# handle arguments to the subcommands.
case $words[1] in
start|restart|reload|stop|status|try-restart|reload-or-restart|reload-or-try-restart|isolate|kill|is-active|show|reset-failed|enable|disable|is-enabled|load)
# many units can be listed
_arguments "*:key:_systemd_units"
;;
cancel) _arguments "*:key:_systemd_jobs" ;;
# snapshots
snapshot) _normal ;;
delete) _arguments "*:key:_systemd_snapshots" ;;
# no arguments
dump|dot|monitor|daemon-reload|daemon-reexec|show-environment|default|rescue|emergency|halt|poweroff|reboot|kexec|exit|list-jobs|list-units)
;;
*) _message "unknown systemctl command: $words[1]" ;;
esac
}
_systemctl "$@"
prev parent reply other threads:[~2011-08-17 15:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-29 12:10 Anthony R Fletcher
2011-08-17 15:09 ` Anthony R Fletcher [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110817150945.GA25599@cosy.cit.nih.gov \
--to=arif@mail.nih.gov \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).