fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Fabian Boehmcompletions/systemctl: List disabled units for start as welle36684786

master
4.4 KiB88 linesraw
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
4    set -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.
8    set -l opts t/type= s-state= p/property= a/all
9    set opts $opts r/recursive R-reverse A-after B-before
10    set opts $opts l/full V-value S-show-types J-job-mode=
11    set opts $opts F-fail i/ignore-inhibitors q/quiet N-no-block
12    set opts $opts W-wait U-user Y-system I-failed O-no-wall
13    set opts $opts G-global E-reload K-no-ask-password 4-kill-who
14    set opts $opts ü-signal f-force 5-message ö-now ä-root
15    set opts $opts Ü-runtime Ö-preset-mode= n/lines= o/output=
16    set opts $opts Ä-firmware-setup ß-plain H/host= M/machine=
17    set opts $opts 1-no-pager 2-no-legend h/help 3-version
18
19    set -l args $argv
20    set -l cmdline (commandline -xpc) (commandline -ct)
21    set -e cmdline[1]
22    argparse $opts -- $cmdline 2>/dev/null
23    or return
24
25    # If no subcommand has been given, return so this can be used as a condition.
26    test -n "$argv[1]"
27    or return
28    set -l cmd $argv[1]
29    set -e argv[1]
30
31    # Flags we want to pass on.
32    set -l passflags $_flag_user $_flag_system $_flag_failed
33    switch "$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.
36        case 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
38        case enable
39            # This will only work for "list-unit-files", but won't print an error for "list-units".
40            set -q _flag_state; or set _flag_state disabled
41        case disable
42            set -q _flag_state; or set _flag_state enabled
43        case start
44            # Running `start` on an already started unit isn't an _error_, but useless.
45            set -q _flag_state; or set _flag_state dead,failed,disabled
46        case mask
47            set -q _flag_state; or set _flag_state loaded
48        case unmask
49            set -q _flag_state; or set _flag_state masked
50        case 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.
53            set -q _flag_state; or set _flag_state running,mounted,active
54        case isolate set-default
55            # These only take one unit.
56            set -q argv[1]; and return
57        case list-sockets
58            set _flag_type socket
59        case list-timers
60            set _flag_type timer
61        case 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.
64            return
65        case '*'
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.
68            return
69    end
70
71    # Add the flags back so we can pass them to our systemctl invocations.
72    set -q _flag_type; and set passflags $passflags --type=$_flag_type
73    set -q _flag_state; and set passflags $passflags --state=$_flag_state
74    set -q _flag_property; and set passflags $passflags --property=$_flag_property
75    set -q _flag_machine; and set passflags $passflags --machine=$_flag_machine
76    set -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.
81    systemctl --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.
87    systemctl --full --no-legend --no-pager --plain --all list-unit-files $passflags | string replace -r "(?: +(\S+)){1}" \t'$1'
88end