fork/fish-shell

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

Fabian Boehmcompletions: More shortening5dc07c9e7

master
11.3 KiB277 linesraw
1# Completions for `snap` command
2
3function __fish_snap_no_subcommand -d 'Test if snap has yet to be given the subcommand'
4    for i in (commandline -xpc)
5        if contains -- $i abort ack alias aliases buy changes connect disable disconnect download \
6                enable find get help info install interfaces known list login logout prefer refresh remove \
7                revert run set tasks try unalias version watch
8            return 1
9        end
10    end
11    return 0
12end
13
14function __fish_snap_using_subcommand -d 'Test if given subcommand is used'
15    for i in (commandline -xpc)
16        if contains -- $i $argv[1]
17            return 0
18        end
19    end
20    return 1
21end
22
23function __fish_snap_use_file -d 'Test if snap command should have files as potential completion'
24    for i in (commandline -xpc)
25        if contains -- $i ack try
26            return 0
27        end
28    end
29    return 1
30end
31
32function __fish_snap_subcommand
33    set -l subcommand $argv[1]
34    set -e argv[1]
35    complete -f -c snap -n __fish_snap_no_subcommand -a $subcommand $argv
36end
37
38function __fish_snap_option
39    set -l subcommand $argv[1]
40    set -e argv[1]
41    complete -f -c snap -n "__fish_snap_using_subcommand $subcommand" $argv
42end
43
44function __fish_snap_disabled_snaps -d 'List disabled snaps'
45    snap list | string match "*disabled" | string replace -r '(.+?) .*disabled' '$1'
46end
47
48function __fish_snap_enabled_snaps -d 'List disabled snaps'
49    snap list | string match -vr "disabled|Name" | string replace -r '(.+?) .*' '$1'
50end
51
52function __fish_snap_installed_snaps -d 'List installed snaps'
53    snap list | string replace -r '(.+?) .*' '$1' | string match -v 'Name*'
54end
55
56function __fish_snap_interfaces -d 'List of interfaces'
57    for snap in (__fish_snap_installed_snaps)
58        if test $snap != core
59            snap interfaces $snap 2>/dev/null | string replace -r '[- ]*([^ ]*)[ ]+([^ ]+)' '$2$1' | string match -v "*Slot*"
60        end
61    end
62end
63
64function __fish_snap_change_id -d 'List change IDs'
65    snap changes | string match -v 'ID*' | string replace -r '([0-9]*) .*' '$1'
66end
67
68function __fish_snap_aliases -d 'List aliases'
69    snap aliases | string match -v 'Command*' | string replace -r '.* (.+?) .*$' '$1'
70    snap aliases | string match -v 'Command*' | string replace -r '(.*?) .*$' '$1'
71end
72
73function __fish_snap_no_assertion -d 'Check that no assertion type is used yet'
74    for i in (commandline -xpc)
75        if contains -- $i account account-key model serial snap-declaration snap-build snap-revision \
76                system-user validation
77            return 1
78        end
79    end
80    return 0
81end
82
83function __fish_snap_using_assertion -d 'Check if certain assertion type is used'
84    if __fish_snap_using_subcommand known
85        if __fish_snap_using_subcommand $argv[1]
86            return 0
87        end
88    end
89    return 1
90end
91
92function __fish_snap_assertion
93    set -l assertion $argv[1]
94    set -e argv[1]
95    complete -f -c snap -n '__fish_snap_using_subcommand known; and __fish_snap_no_assertion' -a $assertion
96    complete -f -c snap -n "__fish_snap_using_assertion $assertion" -a "(__fish_snap_filters $assertion)" \
97        -d Filter
98end
99
100function __fish_snap_filters -d 'List assertion filters'
101    snap known $argv[1] | string match -v 'type:*' | string match '*: *' | string replace -r '(.*): (.*)' '$1=$2'
102end
103
104# Enable file completions where appropriate
105complete -c snap -n __fish_snap_use_file -a '(__fish_complete_path)'
106
107# Support flags
108complete -x -f -c snap -s h -l help -d 'Show this help message'
109complete -x -f -c snap -s v -l version -d 'Print the version and exit'
110
111# Abort
112__fish_snap_subcommand abort -d "Abort a pending change"
113
114# Ack
115__fish_snap_subcommand ack -r -d "Adds an assertion to the system"
116
117# Alias
118__fish_snap_subcommand alias -r -d "Sets up a manual alias"
119__fish_snap_option alias -a '(__fish_snap_installed_snaps)' -d Snap
120
121# Aliases
122__fish_snap_subcommand aliases -d "Lists aliases in the system"
123
124# Buy
125__fish_snap_subcommand buy -r -d "Buys a snap"
126
127# Changes
128__fish_snap_subcommand changes -d "List system changes"
129
130# Connect
131__fish_snap_subcommand connect -r -d "Connects a plug to a slot"
132__fish_snap_option connect -a '(__fish_snap_interfaces)' -d "Snap:Plug or Slot"
133
134# Disable
135__fish_snap_subcommand disable -r -d "Disables a snap in the system"
136__fish_snap_option disable -a '(__fish_snap_enabled_snaps)' -d "Enabled snap"
137
138# Disconnect
139__fish_snap_subcommand disconnect -r -d "Disconnects a plug from a slot"
140__fish_snap_option disconnect -a '(__fish_snap_interfaces)' -d "Snap:Plug or Slot"
141
142# Downloads
143__fish_snap_subcommand download -r -d "Downloads the given snap"
144__fish_snap_option download -l channel -d "Use this channel instead of stable"
145__fish_snap_option download -l edge -d "Install from the edge channel"
146__fish_snap_option download -l beta -d "Install from the beta channel"
147__fish_snap_option download -l candidate -d "Install from the candidate channel"
148__fish_snap_option download -l stable -d "Install from the stable channel"
149__fish_snap_option download -l revision -d "Download the given revision of snap, to which you must have developer access"
150
151# Enable
152__fish_snap_subcommand enable -r -d "Enables a snap in the system"
153__fish_snap_option enable -a '(__fish_snap_disabled_snaps)' -d "Disabled snap"
154
155# Find
156__fish_snap_subcommand find -r -d "Finds packages to install"
157__fish_snap_option find -l private -d "Search private snaps"
158__fish_snap_option find -l section -d "Restrict the search to a given section"
159
160# There seems to be no programmatic way of getting configuration options
161# Get
162__fish_snap_subcommand get -r -d "Prints configuration options"
163__fish_snap_option get -s t -d "Strict typing with nulls and quoted strings"
164__fish_snap_option get -s d -d "Always return documents, even with single key"
165__fish_snap_option get -a '(__fish_snap_installed_snaps)' -d Snap
166
167# Help
168__fish_snap_subcommand help -d "The help command shows useful information"
169__fish_snap_option help -l man -d "Generates the manpage"
170
171# Info
172__fish_snap_subcommand info -r -d "Show detailed information about a snap"
173__fish_snap_option info -l verbose -d "Include a verbose list of snap's notes"
174__fish_snap_option info -a '(__fish_snap_installed_snaps)' -d Snap
175
176# Install
177__fish_snap_subcommand install -r -d "Installs a snap to the system"
178__fish_snap_option install -l channel -d "Use this channel instead of stable"
179__fish_snap_option install -l edge -d "Install from the edge channel"
180__fish_snap_option install -l beta -d "Install from the beta channel"
181__fish_snap_option install -l candidate -d "Install from the candidate channel"
182__fish_snap_option install -l stable -d "Install from the stable channel"
183__fish_snap_option install -l revision -d "Install the given revision of snap, to which you must have developer access"
184__fish_snap_option install -l devmode -d "Put snap in development mode and disable security confinement"
185__fish_snap_option install -l jailmode -d "Put snap in enforced confinement mode"
186__fish_snap_option install -l classic -d "Put snap in classic mode and disable security confinement"
187__fish_snap_option install -l dangerous -d "Install the given snap even without pre-acknowledged signatures (DANGEROUS)"
188
189# Interfaces
190__fish_snap_subcommand interfaces -d "Lists interfaces in the system"
191complete -f -c snap -n '__fish_snap_using_subcommand interfaces' -a '(__fish_snap_installed_snaps)' -d Snap
192__fish_snap_option interfaces -s i -d "Constrain listing to specific interfaces"
193
194# Known
195__fish_snap_subcommand known -r -d "Shows known assertions of the provided type"
196__fish_snap_option known -l remote -d "Shows known assertions of the provided type"
197__fish_snap_assertion account -d 'Assertion type'
198__fish_snap_assertion account-key -d 'Assertion type'
199__fish_snap_assertion model -d 'Assertion type'
200__fish_snap_assertion serial -d 'Assertion type'
201__fish_snap_assertion snap-declaration -d 'Assertion type'
202__fish_snap_assertion snap-build -d 'Assertion type'
203__fish_snap_assertion snap-revision -d 'Assertion type'
204__fish_snap_assertion system-user -d 'Assertion type'
205__fish_snap_assertion validation -d 'Assertion type'
206
207# List
208__fish_snap_subcommand list -d "List installed snaps"
209__fish_snap_option list -l all -d "Show all revisions"
210
211# Login
212__fish_snap_subcommand login -d "Authenticates on snapd and the store"
213
214# Logout
215__fish_snap_subcommand logout -d "Log out of the store"
216
217# Prefer
218__fish_snap_subcommand prefer -r -d "Prefes aliases from a snap and disable conflicts"
219__fish_snap_option prefer -a '(__fish_snap_installed_snaps)' -d Snap
220
221# Refresh
222__fish_snap_subcommand refresh -r -d "Refreshes a snap in the system"
223__fish_snap_option refresh -l channel -d "Use this channel instead of stable"
224__fish_snap_option refresh -l edge -d "Install from the edge channel"
225__fish_snap_option refresh -l beta -d "Install from the beta channel"
226__fish_snap_option refresh -l candidate -d "Install from the candidate channel"
227__fish_snap_option refresh -l stable -d "Install from the stable channel"
228__fish_snap_option refresh -l revision -d "Refresh to the given revision"
229__fish_snap_option refresh -l devmode -d "Put snap in development mode and disable security confinement"
230__fish_snap_option refresh -l jailmode -d "Put snap in enforced confinement mode"
231__fish_snap_option refresh -l classic -d "Put snap in classic mode and disable security confinement"
232__fish_snap_option refresh -l ignore-validation -d "Ignore validation by other snaps blocking the refresh"
233__fish_snap_option refresh -a '(__fish_snap_installed_snaps)' -d Snap
234
235# Remove
236__fish_snap_subcommand remove -r -d "Removes a snap from the system"
237__fish_snap_option remove -l revision -d "Removes only the given revision"
238__fish_snap_option remove -a '(__fish_snap_installed_snaps)' -d Snap
239
240# Revert
241__fish_snap_subcommand revert -r -d "Revert the given snap to the previous state"
242__fish_snap_option refresh -l revision -d "Revert to the given revision"
243__fish_snap_option refresh -l devmode -d "Put snap in development mode and disable security confinement"
244__fish_snap_option refresh -l jailmode -d "Put snap in enforced confinement mode"
245__fish_snap_option refresh -l classic -d "Put snap in classic mode and disable security confinement"
246__fish_snap_option revert -a '(__fish_snap_installed_snaps)' -d Snap
247
248# Run
249__fish_snap_subcommand run -r -d "Run the given snap command"
250__fish_snap_option run -l shell -d "Run a shell instead of the command (useful for debugging)"
251__fish_snap_option run -a '(__fish_snap_installed_snaps)' -d Snap
252
253# There seems to be no programmatic way of getting configuration options
254# Set
255__fish_snap_subcommand set -r -d "Changes configuration options"
256__fish_snap_option set -a '(__fish_snap_installed_snaps)' -d Snap
257
258# Tasks
259__fish_snap_subcommand tasks -d "List a change's tasks"
260__fish_snap_option tasks -a '(__fish_snap_change_id)' -d ID
261
262# Try
263__fish_snap_subcommand try -r -d "Tests a snap in the system"
264__fish_snap_option try -l devmode -d "Put snap in development mode and disable security confinement"
265__fish_snap_option try -l jailmode -d "Put snap in enforced confinement mode"
266__fish_snap_option try -l classic -d "Put snap in classic mode and disable security confinement"
267
268# Unalias
269__fish_snap_subcommand unalias -r -d "Unalias a manual alias or an entire snap"
270__fish_snap_option unalias -a '(__fish_snap_aliases)' -d "Alias or snap"
271
272# Version
273__fish_snap_subcommand version -d "Shows version details"
274
275# Watch
276__fish_snap_subcommand watch -d "Watch a change in progress"
277__fish_snap_option watch -a '(__fish_snap_change_id)' -d ID