fork/fish-shell

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

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

master
14.5 KiB253 linesraw
1# Returns exit code of 0 if apm hasn't received a command yet, e.g. `config`
2function __fish_apm_needs_command
3    set -l cmd (commandline -xpc)
4    if test (count $cmd) -eq 1
5        return 0
6    else if test (count $cmd) -gt 1
7        for c in $cmd[2..-1]
8            switch $c
9                # Exclude options that are allowed to appear before command
10                case --color --no-color help
11                    continue
12                case '*'
13                    return 1
14            end
15        end
16        return 0
17    end
18    return 1
19end
20
21# Returns exit code of 0 if any command (argv[1..-1]) appears once, ignores flags.
22function __fish_apm_using_command
23    set -l commands $argv
24    set -l cmd (commandline -xpc)
25    if test (count $cmd) -gt 1
26        set -l command_seen_once 1
27        for c in $cmd[2..-1]
28            switch $c
29                case '-*'
30                    continue
31                case $commands
32                    # If the command is seen more than once then return 1
33                    if test $command_seen_once -eq 1
34                        set command_seen_once 0
35                    else
36                        return 1
37                    end
38                case '*'
39                    if test $command_seen_once -eq 0
40                        return 0
41                    else
42                        return 1
43                    end
44            end
45        end
46        return $command_seen_once
47    end
48    return 1
49end
50
51# Check if `commandline` contains a set of subcommands
52function __fish_apm_includes_subcommand
53    set -l cmd (commandline -xpc)
54    for subcommand in $argv
55        if contains $subcommand $cmd
56            return 0
57        end
58    end
59    return 1
60end
61
62# Lists all apm config items
63function __fish_apm_config_items
64    apm config list | string match -r -v "^\s*;|^\s*\$" | string replace "\w*=\w*" \t
65end
66
67# Lists all installed atom packages
68function __fish_apm_list_packages
69    apm list -b
70end
71
72if apm -h 2>| string match -q "*Atom Package Manager*"
73    # Completions for Atom Package Manager
74
75    ##################
76    # global options #
77    ##################
78
79    # help
80    complete -f -c apm -n __fish_apm_needs_command -s h -l help -d "Display help"
81    complete -f -c apm -n __fish_apm_needs_command -a help -d "Display help"
82    complete -f -c apm -n '__fish_apm_using_command clean config dedupe deinstall delete dev develop docs erase featured home init install link linked links list ln lns login ls open outdated publish rebuild rebuild-module-cache remove rm search show star starred stars test uninstall unlink unpublish unstar update upgrade view' -s h -l help -d 'Display help'
83
84    # version
85    complete -f -c apm -n __fish_apm_needs_command -s v -l version -d "Display version"
86
87    # color
88    complete -f -c apm -n __fish_apm_needs_command -l color -d "Enable colored output"
89    complete -f -c apm -n __fish_apm_needs_command -l no-color -d "Disable colored output"
90
91    ############
92    # commands #
93    ############
94
95    # clean
96    complete -f -c apm -n __fish_apm_needs_command -a clean -d "Deletes packages in node_modules not referenced
97as dependency in package.json"
98
99    # config
100    set -l config_subcommands "get set edit delete list"
101    complete -f -c apm -n __fish_apm_needs_command -a config -d "Modify or list configuration items"
102    complete -x -c apm -n "__fish_apm_using_command config; and not __fish_apm_includes_subcommand $config_subcommands" -a set -d 'Set config item'
103    complete -x -c apm -n "__fish_apm_using_command config; and not __fish_apm_includes_subcommand $config_subcommands" -a get -d 'Get config item'
104    complete -x -c apm -n "__fish_apm_using_command config; and not __fish_apm_includes_subcommand $config_subcommands" -a delete -d 'Delete config item'
105    complete -x -c apm -n "__fish_apm_using_command config; and not __fish_apm_includes_subcommand $config_subcommands" -a list -d 'List config items'
106    complete -x -c apm -n "__fish_apm_using_command config; and not __fish_apm_includes_subcommand $config_subcommands" -a edit -d 'Edit config items'
107    complete -x -c apm -n '__fish_apm_using_command config set get delete; and __fish_apm_includes_subcommand set get delete' -a '(__fish_apm_config_items)'
108
109    # dedupe
110    complete -f -c apm -n __fish_apm_needs_command -a dedupe -d "Reduce duplication in node_modules in current directory"
111
112    # deinstall & delete & erase & remove & rm & uninstall
113    set -l uninstall_commands "deinstall delete erase remove rm uninstall"
114    complete -f -c apm -n __fish_apm_needs_command -a $uninstall_commands -d "Delete installed package(s) from ~/.atom/packages"
115    complete -f -c apm -n "__fish_apm_using_command $uninstall_commands" -a '(__fish_apm_list_packages)'
116    complete -f -c apm -n "__fish_apm_using_command $uninstall_commands" -l hard -d "Unlink package from ~/.atom/packages and ~/.atom/dev/packages"
117    complete -f -c apm -n "__fish_apm_using_command $uninstall_commands" -s d -l dev -d "Unlink package from ~/.atom/dev/packages"
118
119    # dev(elop)
120    set -l dev_commands "dev develop"
121    complete -f -c apm -n __fish_apm_needs_command -a $dev_commands -d "Clone install dependencies and link a package for development"
122    complete -f -c apm -n "__fish_apm_using_command $dev_commands" -a '(__fish_apm_list_packages)'
123
124    # docs & home & open
125    set -l open_commands "docs home open"
126    complete -f -c apm -n __fish_apm_needs_command -a $open_commands -d "Open a package's homepage in the default browser"
127    complete -f -c apm -n "__fish_apm_using_command $open_commands" -s p -l print -d "Print URL instead of opening"
128    complete -f -c apm -n "__fish_apm_using_command $open_commands" -a '(__fish_apm_list_packages)'
129
130    # featured
131    complete -f -c apm -n __fish_apm_needs_command -a featured -d "List Atom packages and themes currently featured in the
132atom.io registry"
133    complete -f -c apm -n '__fish_apm_using_command featured' -l json -d "Output featured packages as JSON array"
134    complete -f -c apm -n '__fish_apm_using_command featured' -s t -l themes -d "Only list themes"
135    complete -x -c apm -n '__fish_apm_using_command featured' -s c -l compatible -d "Only list packages/themes compatible with specified Atom version"
136
137    # init
138    complete -f -c apm -n __fish_apm_needs_command -a init -d "Generates code scaffolding for theme or package"
139    complete -r -c apm -n '__fish_apm_using_command init' -l template -d "Path to the package or theme template"
140    complete -x -c apm -n '__fish_apm_using_command init' -s p -l package -d "Generates a basic package"
141    complete -x -c apm -n '__fish_apm_using_command init' -s t -l theme -d "Generates a basic theme"
142    complete -x -c apm -n '__fish_apm_using_command init' -s l -l language -d "Generates a basic language package"
143    complete -r -c apm -n '__fish_apm_using_command init' -s c -l convert -d "Convert TextMate bundle/theme"
144
145    # install
146    complete -f -c apm -n __fish_apm_needs_command -a install -d "Install Atom package to ~/.atom/packages/<package_name>"
147    complete -f -c apm -n '__fish_apm_using_command install' -l check -d "Check native build tools are installed"
148    complete -f -c apm -n '__fish_apm_using_command install' -l verbose -d "Show verbose debug information"
149    complete -r -c apm -n '__fish_apm_using_command install' -l packages-file -d "Specify text file containing packages to install"
150    complete -f -c apm -n '__fish_apm_using_command install' -l production -d "Do not install dev dependencies"
151    complete -x -c apm -n '__fish_apm_using_command install' -s c -l compatible -d "Only install packages/themes compatible with specified Atom version"
152    complete -f -c apm -n '__fish_apm_using_command install' -s s -l silent -d "Set npm log level to silent"
153    complete -f -c apm -n '__fish_apm_using_command install' -s q -l quiet -d "Set npm log level to quiet"
154
155    # link & ln
156    set -l link_commands "link ln"
157    complete -f -c apm -n __fish_apm_needs_command -a $link_commands -d "Create a symlink for the package in ~/.atom/packages"
158    complete -f -c apm -n "__fish_apm_using_command $link_commands" -s d -l dev -d "Link to ~/.atom/dev/packages"
159
160    # linked & links & lns
161    set -l linked_commands "linked links lns"
162    complete -f -c apm -n __fish_apm_needs_command -a $linked_commands -d "List all symlinked packages in ~/.atom/packages and
163~/.atom/dev/packages"
164
165    # list & ls
166    set -l list_commands "list ls"
167    complete -f -c apm -n __fish_apm_needs_command -a $list_commands -d "List all installed and bundled packages"
168    complete -f -c apm -n "__fish_apm_using_command $list_commands" -s b -l bare -d "Print packages one per line with no formatting"
169    complete -f -c apm -n "__fish_apm_using_command $list_commands" -s d -l dev -d "Include dev packages"
170    complete -f -c apm -n "__fish_apm_using_command $list_commands" -s i -l installed -d "Only list installed packages/themes"
171    complete -f -c apm -n "__fish_apm_using_command $list_commands" -s j -l json -d "Output all packages as a JSON object"
172    complete -f -c apm -n "__fish_apm_using_command $list_commands" -s l -l links -d "Include linked packages"
173    complete -f -c apm -n "__fish_apm_using_command $list_commands" -s t -l themes -d "Only list themes"
174    complete -f -c apm -n "__fish_apm_using_command $list_commands" -s p -l packages -d "Only list packages"
175
176    # login
177    complete -f -c apm -n __fish_apm_needs_command -a login -d "Save Atom API token to keychain"
178    complete -x -c apm -n "__fish_apm_using_command login" -l token -d "Specify API token"
179
180    # outdated & upgrade & update
181    set -l upgrade_commands "outdated upgrade update"
182    complete -f -c apm -n __fish_apm_needs_command -a $upgrade_commands -d "Upgrade out of date packages"
183    complete -f -c apm -n "__fish_apm_using_command $upgrade_commands" -l json -d "Output outdated packages as JSON array"
184    complete -x -c apm -n "__fish_apm_using_command $upgrade_commands" -l compatible -d "Only install packages/themes compatible with specified Atom version"
185    complete -f -c apm -n "__fish_apm_using_command $upgrade_commands" -l verbose -d "Show verbose debug information"
186    complete -f -c apm -n "__fish_apm_using_command $upgrade_commands" -s c -l confirm -d "Confirm before installing updates"
187    complete -f -c apm -n "__fish_apm_using_command $upgrade_commands" -s l -l list -d "List but don't install the outdated packages"
188
189    # publish
190    set -l publish_subcommands "major minor patch build"
191    complete -f -c apm -n __fish_apm_needs_command -a publish -d "Publish new version of package in current working directory"
192    complete -f -c apm -n "__fish_apm_using_command publish; and not __fish_apm_includes_subcommand $publish_subcommands" -a $publish_subcommands -d "Semantic version category for new version"
193    complete -x -c apm -n '__fish_apm_using_command publish' -s t -l tag -d "Specify a tag to publish"
194    complete -x -c apm -n '__fish_apm_using_command publish' -s r -l rename -d "Specify a new name for the package"
195
196    # rebuild
197    complete -f -c apm -n __fish_apm_needs_command -a rebuild -d "Rebuild modules installed in node_modules in current working directory"
198
199    # rebuild-module-cache
200    complete -f -c apm -n __fish_apm_needs_command -a rebuild-module-cache -d "Rebuild module cache for installed packages"
201
202    # search
203    complete -f -c apm -n __fish_apm_needs_command -a search -d "Search for Atom packages/themes in the atom.io registry"
204    complete -f -c apm -n '__fish_apm_using_command search' -l json -d "Output matching packages as JSON array"
205    complete -f -c apm -n '__fish_apm_using_command search' -s p -l packages -d "Search only non-theme packages"
206    complete -f -c apm -n '__fish_apm_using_command search' -s t -l themes -d "Search only themes"
207
208    # show & view
209    set -l show_commands "show view"
210    complete -f -c apm -n __fish_apm_needs_command -a $show_commands -d "View information about package/theme in the atom.io registry"
211    complete -f -c apm -n "__fish_apm_using_command $show_commands" -l json -d "Output as JSON array"
212    complete -x -c apm -n "__fish_apm_using_command $show_commands" -l compatible -d "Show latest version compatible with specified Atom version"
213
214    # star
215    complete -f -c apm -n __fish_apm_needs_command -a star -d "Star the given packages on https://atom.io"
216    complete -f -c apm -n '__fish_apm_using_command star' -l installed -d "Star all packages in ~/.atom/packages"
217
218    # starred & stars
219    set -l stars_commands "starred stars"
220    complete -f -c apm -n __fish_apm_needs_command -a $stars_commands -d "List or install starred Atom packages and themes"
221    complete -f -c apm -n "__fish_apm_using_command $stars_commands" -l json -d "Output packages as JSON array"
222    complete -f -c apm -n "__fish_apm_using_command $stars_commands" -s i -l install -d "Install the starred packages"
223    complete -f -c apm -n "__fish_apm_using_command $stars_commands" -s t -l themes -d "Only list themes"
224    complete -x -c apm -n "__fish_apm_using_command $stars_commands" -s u -l user -d "GitHub username to show starred packages for"
225
226    # test
227    complete -f -c apm -n __fish_apm_needs_command -a test -d "Runs the package's tests contained within the spec directory"
228    complete -r -c apm -n '__fish_apm_using_command test' -s p -l path -d "Path to atom command"
229
230    # unlink
231    complete -f -c apm -n __fish_apm_needs_command -a unlink -d "Delete the symlink in ~/.atom/packages for the package"
232    complete -f -c apm -n '__fish_apm_using_command unlink' -l hard -d "Unlink package from ~/.atom/packages and ~/.atom/dev/packages"
233    complete -f -c apm -n '__fish_apm_using_command unlink' -s d -l dev -d "Unlink package from ~/.atom/dev/packages"
234    complete -f -c apm -n '__fish_apm_using_command unlink' -s a -l all -d "Unlink all packages in ~/.atom/packages and ~/.atom/dev/packages"
235
236    # unpublish
237    complete -f -c apm -n __fish_apm_needs_command -a unpublish -d "Remove published package or version from the atom.io registry"
238    complete -f -c apm -n '__fish_apm_using_command unpublish' -s f -l force -d "Do not prompt for confirmation"
239
240    # unstar
241    complete -f -c apm -n __fish_apm_needs_command -a unstar -d "Unstar given packages on https://atom.io"
242
243else
244    # Completions for the Advanced Power Management client
245
246    complete -f -c apm -s V -l version -d "Display version and exit"
247    complete -f -c apm -s v -l verbose -d "Print APM info"
248    complete -f -c apm -s m -l minutes -d "Print time remaining"
249    complete -f -c apm -s M -l monitor -d "Monitor status info"
250    complete -f -c apm -s S -l standby -d "Request APM standby mode"
251    complete -f -c apm -s s -l suspend -d "Request APM suspend mode"
252    complete -f -c apm -s d -l debug -d "APM status debugging info"
253end