diff --git a/CHANGELOG.md b/CHANGELOG.md index ef9f88e9..bde02e6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v7.0.5 - 2018-03-15 + +* Add bash completions #801 [Ronald McCollam] + ## v7.0.4 - 2018-03-15 * Generate consistent working anchors for both our md output & resin docs #813 [Tim Perry] diff --git a/README.md b/README.md index e95287a6..10efb059 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,10 @@ _(Typically useful, but not strictly required for all commands)_ Take a look at the full command documentation at [https://docs.resin.io/tools/cli/](https://docs.resin.io/tools/cli/#table-of-contents ), or by running `resin help`. +### Bash completions + +Optionally you can enable tab completions for the bash shell, enabling the shell to provide additional context and automatically complete arguments to`resin`. To enable bash completions, copy the `resin-completion.bash` file to the default bash completions directory (usually `/etc/bash_completion.d/`) or append it to the end of `~/.bash_completion`. + FAQ --- diff --git a/package.json b/package.json index 097d25e6..23e86cd9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "resin-cli", - "version": "7.0.4", + "version": "7.0.5", "description": "The official resin.io CLI tool", "main": "./build/actions/index.js", "homepage": "https://github.com/resin-io/resin-cli", diff --git a/resin-completion.bash b/resin-completion.bash new file mode 100644 index 00000000..1dccac79 --- /dev/null +++ b/resin-completion.bash @@ -0,0 +1,73 @@ +#!/bin/bash + +_resin_complete() +{ + local cur prev + + # Valid top-level completions + commands="app apps build config deploy device devices env envs help key \ + keys local login logout logs note os preload quickstart settings \ + signup ssh sync util version whoami" + # Sub-completions + app_cmds="create restart rm" + config_cmds="generate inject read reconfigure write" + device_cmds="identify init move public-url reboot register rename rm \ + shutdown" + device_public_url_cmds="disable enable status" + env_cmds="add rename rm" + key_cmds="add rm" + local_cmds="configure flash logs push scan ssh stop" + os_cmds="build-config configure download initialize versions" + util_cmds="available-drives" + + + COMPREPLY=() + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + if [ $COMP_CWORD -eq 1 ] + then + COMPREPLY=( $(compgen -W "${commands}" -- $cur) ) + elif [ $COMP_CWORD -eq 2 ] + then + case "$prev" in + "app") + COMPREPLY=( $(compgen -W "$app_cmds" -- $cur) ) + ;; + "config") + COMPREPLY=( $(compgen -W "$config_cmds" -- $cur) ) + ;; + "device") + COMPREPLY=( $(compgen -W "$device_cmds" -- $cur) ) + ;; + "env") + COMPREPLY=( $(compgen -W "$env_cmds" -- $cur) ) + ;; + "key") + COMPREPLY=( $(compgen -W "$key_cmds" -- $cur) ) + ;; + "local") + COMPREPLY=( $(compgen -W "$local_cmds" -- $cur) ) + ;; + "os") + COMPREPLY=( $(compgen -W "$os_cmds" -- $cur) ) + ;; + "util") + COMPREPLY=( $(compgen -W "$util_cmds" -- $cur) ) + ;; + "*") + ;; + esac + elif [ $COMP_CWORD -eq 3 ] + then + case "$prev" in + "public-url") + COMPREPLY=( $(compgen -W "$device_public_url_cmds" -- $cur) ) + ;; + "*") + ;; + esac + fi + +} +complete -F _resin_complete resin