From 8624ff74d9af970fe7a4d2a5a5f16d8695794e28 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 24 Dec 2014 09:15:27 -0400 Subject: [PATCH] Implement Bash/Zsh basic autocompletion --- completion/resin.sh | 41 ++++++++++++++++++++++ doc/resin-completion.1.md | 34 ++++++++++++++++++ doc/resin-completion.1.roff | 69 +++++++++++++++++++++++++++++++++++++ package.json | 3 +- 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 completion/resin.sh create mode 100644 doc/resin-completion.1.md create mode 100644 doc/resin-completion.1.roff diff --git a/completion/resin.sh b/completion/resin.sh new file mode 100644 index 00000000..106e41bb --- /dev/null +++ b/completion/resin.sh @@ -0,0 +1,41 @@ +_resin() { + COMPREPLY=() + + local current="${COMP_WORDS[COMP_CWORD]}" + local previous="${COMP_WORDS[COMP_CWORD-1]}" + local options="app device key envs os example" + + case "${previous}" in + app) + local subcommands="create rm restart" + COMPREPLY=( $(compgen -W "${subcommands}" -- ${current}) ) + return 0 ;; + device) + local subcommands="rename rm identify" + COMPREPLY=( $(compgen -W "${subcommands}" -- ${current}) ) + return 0 ;; + key) + local subcommands="add rm" + COMPREPLY=( $(compgen -W "${subcommands}" -- ${current}) ) + return 0 ;; + envs) + local subcommands="add rename rm" + COMPREPLY=( $(compgen -W "${subcommands}" -- ${current}) ) + return 0 ;; + os) + local subcommands="download" + COMPREPLY=( $(compgen -W "${subcommands}" -- ${current}) ) + return 0 ;; + example) + local subcommands="clone" + COMPREPLY=( $(compgen -W "${subcommands}" -- ${current}) ) + return 0 ;; + *) + ;; + esac + + COMPREPLY=( $(compgen -W "${options}" -- ${current}) ) + return 0 +} + +complete -F _resin resin diff --git a/doc/resin-completion.1.md b/doc/resin-completion.1.md new file mode 100644 index 00000000..25a14c85 --- /dev/null +++ b/doc/resin-completion.1.md @@ -0,0 +1,34 @@ +resin(1) - tab completion for resin +=================================== + +## DESCRIPTION + +It provides basic completion capabilities for `zsh` and `bash`.o + +If you're using `bash`, add the following line to your `~/.bashrc`: + + . /path/to/resin/completion/resin.sh. + +or create a symlink like this if you have automatic bash completion set up: + + ln - /path/to/resin/completion/resin.sh /etc/bash-completion.d/resin + +or, perhaps: + + ln - /path/to/resin/completion/resin.sh /usr/local/etc/bash-completion.d/resin + +If you're using `zsh`, add the following to your `~/.zshrc`: + + autoload bashcompinit + bashcompinit + source /path/to/resin/completion/resin.sh + +## RESIN PATH + +`/path/to/resin` refers to the place where resin was globally installed in your system. + +This is usually something like `/usr/lib/node_modules/resin`, or `C:\Users\AppData\Roaming\npm\node_modules\resin` on Windows. + +## COPYRIGHT + +resin is Copyright (C) 2014 Resin.io diff --git a/doc/resin-completion.1.roff b/doc/resin-completion.1.roff new file mode 100644 index 00000000..6532436f --- /dev/null +++ b/doc/resin-completion.1.roff @@ -0,0 +1,69 @@ +.\" Generated with Ronnjs 0.4.0 +.\" http://github.com/kapouer/ronnjs +. +.TH "RESIN" "1" "December 2014" "" "" +. +.SH "NAME" +\fBresin\fR \-\- tab completion for resin +. +.SH "DESCRIPTION" +It provides basic completion capabilities for \fBzsh\fR and \fBbash\fR\|\.o +. +.P +If you\'re using \fBbash\fR, add the following line to your \fB~/\.bashrc\fR: +. +.IP "" 4 +. +.nf +\|\. /path/to/resin/completion/resin\.sh\. +. +.fi +. +.IP "" 0 +. +.P +or create a symlink like this if you have automatic bash completion set up: +. +.IP "" 4 +. +.nf +ln \- /path/to/resin/completion/resin\.sh /etc/bash\-completion\.d/resin +. +.fi +. +.IP "" 0 +. +.P +or, perhaps: +. +.IP "" 4 +. +.nf +ln \- /path/to/resin/completion/resin\.sh /usr/local/etc/bash\-completion\.d/resin +. +.fi +. +.IP "" 0 +. +.P +If you\'re using \fBzsh\fR, add the following to your \fB~/\.zshrc\fR: +. +.IP "" 4 +. +.nf +autoload bashcompinit +bashcompinit +source /path/to/resin/completion/resin\.sh +. +.fi +. +.IP "" 0 +. +.SH "RESIN PATH" +\fB/path/to/resin\fR refers to the place where resin was globally installed in your system\. +. +.P +This is usually something like \fB/usr/lib/node_modules/resin\fR, or \fBC:\\Users\\AppData\\Roaming\\npm\\node_modules\\resin\fR on Windows\. +. +.SH "COPYRIGHT" +resin is Copyright (C) 2014 Resin\.io \fIhttps://resin\.io\fR \ No newline at end of file diff --git a/package.json b/package.json index fe228023..f7f03c4f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ }, "preferGlobal": true, "man": [ - "./doc/resin.1.roff" + "./doc/resin.1.roff", + "./doc/resin-completion.1.roff" ], "bin": { "resin": "./bin/resin"