Skip to content

Instantly share code, notes, and snippets.

@oflow
Last active August 30, 2018 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oflow/1305aaa256af5628c37b7954656c6e6a to your computer and use it in GitHub Desktop.
Save oflow/1305aaa256af5628c37b7954656c6e6a to your computer and use it in GitHub Desktop.
雑なsystemctl補完
compdef _systemctl systemctl
function _systemctl() {
_arguments -C \
'1: :(--help --version
enable disable start stop restart reload \
cat status show kill \
list-units list-timers list-unit-files list-sockets \
daemon-reload \
cancel list-jobs list-machines \
try-restart try-reload-or-restart \
isolate is-active is-failed is-enabled reset-failed \
mask unmask link revert \
edit get-default set-default \
default rescue emergency kexec is-system-running \
halt poweroff reboot suspend hibernate hybrid-sleep)' \
'*:key:_list_unit_files'
_list_unit_files() {
local -a units
if [ "$(echo "$BUFFER" | grep " \(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\)")" ]; then
units=(`ls /usr/lib/systemd/system/ | egrep '\.(service|socket|timer)'`)
_wanted key expl 'units' compadd $units
fi
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment