2017-09-09 00:11:43 +08:00
|
|
|
function _fish_systemctl --description 'Call systemctl with some options from the current commandline'
|
|
|
|
# These options are all global - before or after subcommand/arguments.
|
|
|
|
# There's a bunch of long-only options in here, so we need to be creative with the mandatory short version.
|
|
|
|
set -l opts t/type= s-state= p/property= a/all
|
|
|
|
set opts $opts r/recursive R-reverse A-after B-before
|
|
|
|
set opts $opts l/full V-value S-show-types J-job-mode=
|
|
|
|
set opts $opts F-fail i/ignore-inhibitors q/quiet N-no-block
|
|
|
|
set opts $opts W-wait U-user Y-system I-failed O-no-wall
|
|
|
|
set opts $opts G-global E-reload K-no-ask-password 4-kill-who
|
|
|
|
set opts $opts ü-signal f-force 5-message ö-now ä-root
|
|
|
|
set opts $opts Ü-runtime Ö-preset-mode= n/lines= o/output=
|
|
|
|
set opts $opts Ä-firmware-setup ß-plain H/host= M/machine=
|
|
|
|
set opts $opts 1-no-pager 2-no-legend h/help 3-version
|
|
|
|
|
|
|
|
set -l args $argv
|
|
|
|
set -l cmdline (commandline -opc) (commandline -ct)
|
|
|
|
set -e cmdline[1]
|
2018-04-02 04:42:38 +08:00
|
|
|
argparse $opts -- $cmdline 2>/dev/null
|
2017-09-09 00:11:43 +08:00
|
|
|
or return
|
|
|
|
|
|
|
|
# If no subcommand has been given, return so this can be used as a condition.
|
|
|
|
test -n "$argv[1]"
|
|
|
|
or return
|
|
|
|
set -l cmd $argv[1]
|
|
|
|
set -e argv[1]
|
|
|
|
|
|
|
|
# Flags we want to pass on.
|
|
|
|
set -l passflags $_flag_user $_flag_system $_flag_failed
|
|
|
|
switch "$cmd"
|
|
|
|
# These are the normal commands, so just complete all units.
|
|
|
|
# For "restart" et al, also complete non-running ones, since it can be used regardless of state.
|
|
|
|
case reenable status reload {try-,}{reload-or-,}restart is-{active,enabled,failed} show cat \
|
|
|
|
help reset-failed list-dependencies list-units revert add-{wants,requires} edit
|
|
|
|
case enable
|
|
|
|
# This will only work for "list-unit-files", but won't print an error for "list-units".
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q _flag_state; or set _flag_state disabled
|
2017-09-09 00:11:43 +08:00
|
|
|
case disable
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q _flag_state; or set _flag_state enabled
|
2017-09-09 00:11:43 +08:00
|
|
|
case start
|
|
|
|
# Running `start` on an already started unit isn't an _error_, but useless.
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q _flag_state; or set _flag_state dead,failed
|
2017-09-09 00:11:43 +08:00
|
|
|
case mask
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q _flag_state; or set _flag_state loaded
|
2017-09-09 00:11:43 +08:00
|
|
|
case unmask
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q _flag_state; or set _flag_state masked
|
2017-09-09 00:11:43 +08:00
|
|
|
case stop kill
|
|
|
|
# TODO: Is "kill" useful on other unit types?
|
|
|
|
# Running as the catch-all, "mounted" for .mount units, "active" for .target.
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q _flag_state; or set _flag_state running,mounted,active
|
2017-09-09 00:11:43 +08:00
|
|
|
case isolate set-default
|
|
|
|
# These only take one unit.
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q argv[1]; and return
|
2017-09-09 00:11:43 +08:00
|
|
|
case list-sockets
|
|
|
|
set _flag_type socket
|
|
|
|
case list-timers
|
|
|
|
set _flag_type timer
|
|
|
|
case get-default show-environment daemon-{reload,reexec} is-system-running default rescue emergency halt poweroff kexec \
|
|
|
|
suspend hibernate hybrid-sleep
|
|
|
|
# Accept no arguments.
|
|
|
|
return
|
|
|
|
case '*'
|
|
|
|
# Unknown subcommand. Since we don't want to execute just anything, return.
|
|
|
|
# Note that this could also be a partial token, which is completed elsewhere.
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add the flags back so we can pass them to our systemctl invocations.
|
2019-05-05 19:33:35 +08:00
|
|
|
set -q _flag_type; and set passflags $passflags --type=$_flag_type
|
|
|
|
set -q _flag_state; and set passflags $passflags --state=$_flag_state
|
|
|
|
set -q _flag_property; and set passflags $passflags --property=$_flag_property
|
|
|
|
set -q _flag_machine; and set passflags $passflags --machine=$_flag_machine
|
|
|
|
set -q _flag_host; and set passflags $passflags --host=$_flag_host
|
2017-09-09 00:11:43 +08:00
|
|
|
|
|
|
|
# Output looks like
|
|
|
|
# systemd-tmpfiles-clean.timer [more whitespace] loaded active waiting Daily Cleanup[...]
|
|
|
|
# Use the last part as the description.
|
|
|
|
systemctl --no-legend --no-pager --all list-units $passflags | string replace -r "(?: +(\S+)){4}" \t'$1'
|
|
|
|
# We need this for disabled/static units. Also instance units without an active instance.
|
|
|
|
# Output looks like
|
|
|
|
# systemd-tmpfiles-clean.timer static
|
|
|
|
# Just use the state as the description, since we won't get it here.
|
|
|
|
# This is an issue for units that appear in both.
|
|
|
|
systemctl --no-legend --no-pager --all list-unit-files $passflags | string replace -r "(?: +(\S+)){1}" \t'$1'
|
|
|
|
end
|