From e48722f0bf6eb91055d451fb6c6b9655ff7a2aca Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 19 Apr 2018 18:08:22 -0500 Subject: [PATCH] Add completions for `bower` These are "true" completions, with dynamic completion of available packages to be installed or removed. --- CHANGELOG.md | 6 ++-- share/completions/bower.fish | 63 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 share/completions/bower.fish diff --git a/CHANGELOG.md b/CHANGELOG.md index 331dac0c4..33de6cd20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ This section is for changes merged to the `major` branch that are not also merge - Command substitution output is now limited to 10 MB by default (#3822). - Added completions for - `bd` (#4472) + - `bower` - `configure` - `j` (autojump #4344) - `jhipster` (#4472) @@ -72,9 +73,10 @@ This section is for changes merged to the `major` branch that are not also merge - `git` (#4395, #4396, #4592) - `npm` - `ssh` (#4344) - - `yarn` + - `yarn` -_† for autocompletion of available packages for installation via `npm` or `yarn`, make sure `all-the-package-names` is installed (typically: `sudo npm install -g all-the-package-names`)._ +∗ _`jq` must be installed to complete the list of currently installed `bower` or `yarn` packages_.
+† _to autocomplete the list of packages available for installation with `npm` or `yarn`, `all-the-package-names` must be installed (typically: `sudo npm install -g all-the-package-names`)._ -- diff --git a/share/completions/bower.fish b/share/completions/bower.fish new file mode 100644 index 000000000..e695f6b01 --- /dev/null +++ b/share/completions/bower.fish @@ -0,0 +1,63 @@ +function __bower_cmds + echo -en "cache\tManage bower cache +help\tDisplay help information about Bower +home\tOpens a package homepage into your favorite browser +info\tInfo of a particular package +init\tInteractively create a bower.json file +install\tInstall a package locally +link\tSymlink a package folder +list\tList local packages - and possible updates +login\tAuthenticate with GitHub and store credentials +lookup\tLook up a single package URL by name +prune\tRemoves local extraneous packages +register\tRegister a package +search\tSearch for packages by name +update\tUpdate a local package +uninstall\tRemove a local package +unregister\tRemove a package from the registry +version\tBump a package version +" +end + +function __bower_args + echo -en "-f\tMakes various commands more forceful +--force\tMakes various commands more forceful +-j\tOutput consumable JSON +--json\tOutput consumable JSON +-l\tWhat level of logs to report +--loglevel\tWhat level of logs to report +-o\tDo not hit the network +--offline\tDo not hit the network +-q\tOnly output important information +--quiet\tOnly output important information +-s\tDo not output anything, besides errors +--silent\tDo not output anything, besides errors +-V\tMakes output more verbose +--verbose\tMakes output more verbose +--allow-root\tAllows running commands as root +-v\tOutput Bower version +--version\tOutput Bower version +--no-color\tDisable colors" +end + +function __bower_matching_pkgs + bower search (commandline -ct) | string match -r "\S+[^\s]" | string match -v "Search" +end + +# Output of `bower list` is a) slow, b) convoluted. Use `jq` instead. +function __bower_list_installed + if not type -q jq + return 1 + end + + if not test -e bower.json + return 1 + end + + jq -r '.dependencies | to_entries[] | .key' bower.json +end + +complete -c bower -n "__fish_is_first_token" -x -a '(__bower_cmds)' +complete -c bower -n "__fish_should_complete_args" -x -a '(__bower_args)' +complete -c bower -n "__fish_seen_subcommand_from install" -x -a '(__bower_matching_pkgs)' +complete -c bower -n "__fish_seen_subcommand_from uninstall" -x -a '(__bower_list_installed)'