fork/fish-shell

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

Johannes AltmanningerMerge branch 'completions-to-use-expanded-tokens'a9618477e

master
9.2 KiB126 linesraw
1complete -f -c machinectl
2
3set -l commands list status show start login enable disable poweroff reboot \
4    terminate kill bind copy-{to,from} list-images image-status show-image clone rename read-only remove set-limit pull-{tar,raw,dkr} \
5    {import,export}-{raw,tar} {list,cancel}-transfers shell
6
7function __fish_systemd_has_machine_image
8    set -l images (__fish_systemd_machine_images)
9    for i in $images ".host"
10        # Include ".host" here because it _is_ a valid machine
11        if contains -- $i (commandline -xpc)
12            echo $i
13            return 0
14        end
15    end
16    return 1
17end
18
19function __fish_systemd_has_machine
20    set -l cmd
21    if not count $argv >/dev/null
22        set cmd (commandline -xpc)
23    else
24        set cmd $argv
25    end
26    set -l machines (__fish_systemd_machines)
27    for m in $machines
28        if contains -- $m $cmd
29            echo $m
30            return 0
31        end
32    end
33    return 1
34end
35
36# General options
37complete -x -c machinectl -s H -l host -d 'Execute the operation on a remote host' -a "(__fish_print_hostnames)"
38complete -x -c machinectl -s M -l machine -d 'Execute operation on a VM or container' -a "(__fish_systemd_machines)"
39complete -f -c machinectl -s h -l help -d 'Print a short help and exit'
40complete -f -c machinectl -l version -d 'Print a short version and exit'
41complete -f -c machinectl -l no-pager -d 'Do not pipe output into a pager'
42complete -f -c machinectl -l no-legend -d 'Do not print header and footer'
43complete -f -c machinectl -l no-ask-password -d "Don't ask for password for privileged operations" # might only be valid for certain commands, manpage is vague
44
45# Machine commands
46complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a list -d "List running machines"
47complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a list-images -d "List startable machine images"
48complete -f -c machinectl -n "__fish_seen_subcommand_from list-images" -s a -l all -d "Also show machines starting with a '.'"
49
50complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a status -d "Show information about machine"
51complete -f -c machinectl -n "__fish_seen_subcommand_from status" -s l -l full -d "Do not ellipsize process tree entries"
52complete -x -c machinectl -n "__fish_seen_subcommand_from status" -s n -l lines -d "How many journal lines to show"
53complete -x -c machinectl -n "__fish_seen_subcommand_from status" -s o -l output -d "Formatting of journal output" -a \
54    'short short-iso short-precise short-monotonic verbose export json json-pretty json-sse cat'
55
56complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a show -d "Show properties of machines"
57complete -x -c machinectl -n "__fish_seen_subcommand_from show" -s p -l property -d "Limit to certain properties"
58complete -f -c machinectl -n "__fish_seen_subcommand_from show" -s a -l all -d "Show all properties, even if not set"
59
60complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a start -d "Start machine"
61complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a login -d "Login to a machine"
62complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a enable -d "Enable machine to start at boot"
63complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a disable -d "Disable machine from starting at boot"
64complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a poweroff -d "Poweroff machine"
65complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a reboot -d "Reboot machine"
66complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a terminate -d "Terminate machine (without shutting down)"
67
68complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a kill -d "Send signal to process in a machine"
69complete -x -c machinectl -n "__fish_seen_subcommand_from kill" -l kill-who -d "Choose who to send the signal to" -a 'leader all'
70__fish_make_completion_signals
71complete -x -c machinectl -n "__fish_seen_subcommand_from kill" -s s -l signal -d "Signal to send" -a "$__kill_signals"
72
73complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a bind -d "Bind-mount a directory to a machine"
74complete -f -c machinectl -n "__fish_seen_subcommand_from bind" -l mkdir -d "Create destination directory"
75complete -f -c machinectl -n "__fish_seen_subcommand_from bind" -l read-only -d "Apply read-only mount"
76
77complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a copy-to -d "Copy file or directory to a machine"
78complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a copy-from -d "Copy file or directory from a machine"
79
80complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a shell -d "Open a shell on a machine"
81
82# Image commands
83complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a list-images -d "Show a list of locally installed machines"
84complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a image-status -d "Show information about machine images (human-readable)"
85complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a show-image -d "Show properties of machine images (machine-readable)"
86complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a clone -d "Clone a machine image"
87complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a rename -d "Rename a machine image"
88complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a read-only -d "Mark or unmark machine image as read-only"
89complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a remove -d "Remove machine images"
90complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a set-limit -d "Set size limit for machine image"
91
92# Image transfer commands
93complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a pull-tar -d "Download a .tar container image"
94complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a pull-raw -d "Download a .raw container image"
95complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a pull-dkr -d "Download a .dkr container image"
96complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a import-tar -d "Import a .tar container image"
97complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a import-raw -d "Import a .raw container image"
98complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a export-tar -d "Export a .tar container image"
99complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a export-raw -d "Export a .raw container image"
100complete -f -c machinectl -n "__fish_seen_subcommand_from export-tar export-raw" -l format -d "Specify compression format" -a 'uncompressed xz gzip bzip2'
101complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a list-transfers -d "Show running downloads, imports and exports"
102complete -f -c machinectl -n "not __fish_seen_subcommand_from $commands" -a cancel-transfers -d "Abort running downloads, imports or exports"
103complete -x -c machinectl -n "__fish_seen_subcommand_from pull-{tar,raw}" -l verify -a 'no checksum signature' -d "Verify image with specified method"
104complete -x -c machinectl -n "__fish_seen_subcommand_from pull-dkr" -l verify -a no -d "Verify image (not available for dkr)"
105complete -x -c machinectl -n "__fish_seen_subcommand_from pull-dkr" -l dkr-index-url -d "Specify index server"
106complete -f -c machinectl -n "__fish_seen_subcommand_from pull-{tar,raw,dkr}" -l force -d "Overwrite existing machine image"
107
108# These take a list of _running_ machines
109complete -f -c machinectl -n "__fish_seen_subcommand_from status show poweroff reboot terminate kill" -a "(__fish_systemd_machines)"
110
111# These take a list of _installed_ machines, i.e. "machine images"
112# enable seems to do something with a running machine that's not listed as an image, it seems to be a bug
113# disable is kinda hard, as it's essentially a wrapper around `systemctl disable systemd-nspawn@XXX`, but completing machine images is the least wrong for now
114complete -f -c machinectl -n "__fish_seen_subcommand_from start clone rename image-status show-image remove enable disable" -a "(__fish_systemd_machine_images)"
115
116# These take one machine and then something else
117# bind copy-to copy-from take paths so we're done (almost, copy-from takes a path _on the machine_),
118# while login takes exactly one machine and nothing else, which fish currently doesn't do
119complete -f -c machinectl -n "__fish_seen_subcommand_from login bind copy-to copy-from; and not __fish_systemd_has_machine" -a "(__fish_systemd_machines)"
120
121complete -f -c machinectl -n "__fish_seen_subcommand_from login bind copy-to copy-from shell; and not __fish_systemd_has_machine" -a "(__fish_systemd_machines)"
122# This is imperfect as we print the _local_ users
123complete -f -c machinectl -n "__fish_seen_subcommand_from shell; and not __fish_systemd_has_machine (commandline -xpc | cut -d"@" -f2-)" -a "(__fish_print_users)@(__fish_systemd_machines)"
124
125complete -f -c machinectl -n "__fish_seen_subcommand_from read-only; and not __fish_systemd_has_machine_image" -a "(__fish_systemd_machine_images)"
126complete -f -c machinectl -n "__fish_seen_subcommand_from read-only; and __fish_systemd_has_machine_image" -a "yes no"