fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
e36684786
master
1# localization: skip(private) 2function __fish_systemctl --description'Call systemctl with some options from the current commandline' 3# We don't want to complete with ANSI color codes 4set -lu SYSTEMD_COLORS 5 6# These options are all global - before or after subcommand/arguments. 7# There's a bunch of long-only options in here, so we need to be creative with the mandatory short version. 8set -l opts t/type= s-state= p/property= a/all 9set opts$opts r/recursive R-reverse A-after B-before 10set opts$opts l/full V-value S-show-types J-job-mode= 11set opts$opts F-fail i/ignore-inhibitors q/quiet N-no-block 12set opts$opts W-wait U-user Y-system I-failed O-no-wall 13set opts$opts G-global E-reload K-no-ask-password 4-kill-who 14set opts$opts ü-signal f-force 5-message ö-now ä-root 15set opts$opts Ü-runtime Ö-preset-mode= n/lines= o/output= 16set opts$opts Ä-firmware-setup ß-plain H/host= M/machine= 17set opts$opts 1-no-pager 2-no-legend h/help 3-version 18 19set -l args$argv 20set -l cmdline( commandline -xpc) ( commandline -ct) 21set -e cmdline[ 1 ] 22argparse $opts --$cmdline 2> /dev/null 23or return 24 25# If no subcommand has been given, return so this can be used as a condition. 26test -n " $argv [ 1 ] " 27or return 28set -l cmd$argv [ 1 ] 29set -e argv[ 1 ] 30 31# Flags we want to pass on. 32set -l passflags$_flag_user $_flag_system $_flag_failed 33switch " $cmd " 34# These are the normal commands, so just complete all units. 35# For "restart" et al, also complete non-running ones, since it can be used regardless of state. 36case reenable status reload{ try-,}{ reload-or-,} restart is-{ active, enabled, failed} show cat\ 37 help reset-failed list-dependencies list-units revert add-{ wants, requires} edit clean thaw 38case enable 39# This will only work for "list-unit-files", but won't print an error for "list-units". 40set -q _flag_state;or set _flag_state disabled 41case disable 42set -q _flag_state;or set _flag_state enabled 43case start 44# Running `start` on an already started unit isn't an _error_, but useless. 45set -q _flag_state;or set _flag_state dead,failed,disabled 46case mask 47set -q _flag_state;or set _flag_state loaded 48case unmask 49set -q _flag_state;or set _flag_state masked 50case stop kill freeze 51# TODO: Is "kill" useful on other unit types? 52# Running as the catch-all, "mounted" for .mount units, "active" for .target. 53set -q _flag_state;or set _flag_state running,mounted,active 54case isolate set-default 55# These only take one unit. 56set -q argv[ 1 ] ;and return 57case list-sockets 58set _flag_type socket 59case list-timers 60set _flag_type timer 61case get-default show-environment daemon-{ reload, reexec} is-system-running default rescue emergency halt poweroff kexec\ 62 suspend hibernate hybrid-sleep 63# Accept no arguments. 64return 65case '*' 66# Unknown subcommand. Since we don't want to execute just anything, return. 67# Note that this could also be a partial token, which is completed elsewhere. 68return 69end 70 71# Add the flags back so we can pass them to our systemctl invocations. 72set -q _flag_type;and set passflags$passflags --type=$_flag_type 73set -q _flag_state;and set passflags$passflags --state=$_flag_state 74set -q _flag_property;and set passflags$passflags --property=$_flag_property 75set -q _flag_machine;and set passflags$passflags --machine=$_flag_machine 76set -q _flag_host;and set passflags$passflags --host=$_flag_host 77 78# Output looks like 79# systemd-tmpfiles-clean.timer [more whitespace] loaded active waiting Daily Cleanup[...] 80# Use the last part as the description. 81systemctl --full --no-legend --no-pager --plain --all list-units$passflags | string replace -r"(?: +(\S+)){4}" \t'$1' 82# We need this for disabled/static units. Also instance units without an active instance. 83# Output looks like 84# systemd-tmpfiles-clean.timer static 85# Just use the state as the description, since we won't get it here. 86# This is an issue for units that appear in both. 87systemctl --full --no-legend --no-pager --plain --all list-unit-files$passflags | string replace -r"(?: +(\S+)){1}" \t'$1' 88end