cli: Add bash and zsh autocomplete (#2095)

Fixes #2094
This commit is contained in:
Harshavardhana
2017-03-28 16:57:13 -07:00
committed by GitHub
parent 1a6987558a
commit 3b57e86cd3
4 changed files with 44 additions and 0 deletions
+16
View File
@@ -147,6 +147,8 @@ mc ls play
```
<a name="everyday-use"></a>
## Everyday Use
### Shell aliases
You may add shell aliases to override your common Unix tools.
```sh
@@ -157,6 +159,20 @@ alias mkdir='mc mb'
alias pipe='mc pipe'
```
### Shell autocompletion
You may also download [`autocomplete/bash_autocomplete`](https://raw.githubusercontent.com/minio/mc/master/autocomplete/bash_complete) into `/etc/bash_completion.d/` and rename it to `mc`. Don't forget to source the file to make it active on your current shell.
```sh
sudo wget https://raw.githubusercontent.com/minio/mc/master/autocomplete/bash_complete -O /etc/bash_completion.d/mc
source /etc/bash_completion.d/mc
```
```sh
mc <TAB>
admin config diff ls mirror policy session update watch
cat cp events mb pipe rm share version
```
## Explore Further
- [Minio Client Complete Guide](https://docs.minio.io/docs/minio-client-complete-guide)
- [Minio Quickstart Guide](https://docs.minio.io/docs/minio-quickstart-guide)
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
: ${PROG:=$(basename ${BASH_SOURCE})}
_cli_bash_autocomplete() {
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --compgen )
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _cli_bash_autocomplete $PROG -q
+5
View File
@@ -0,0 +1,5 @@
autoload -U compinit && compinit
autoload -U bashcompinit && bashcompinit
script_dir=$(dirname $0)
source ${script_dir}/bash_autocomplete
+9
View File
@@ -285,6 +285,12 @@ func registerApp() *cli.App {
Usage: "Show help.",
}
cli.BashCompletionFlag = cli.BoolFlag{
Name: "compgen",
Usage: "Enables bash-completion for all commands and subcommands.",
Hidden: true,
}
app := cli.NewApp()
app.Action = func(ctx *cli.Context) {
if strings.HasPrefix(Version, "RELEASE.") {
@@ -293,6 +299,7 @@ func registerApp() *cli.App {
}
cli.ShowAppHelp(ctx)
}
app.HideVersion = true
app.HideHelpCommand = true
app.Usage = "Minio Client for cloud storage and filesystems."
@@ -302,6 +309,8 @@ func registerApp() *cli.App {
app.Flags = append(mcFlags, globalFlags...)
app.CustomAppHelpTemplate = mcHelpTemplate
app.CommandNotFound = commandNotFound // handler function declared above.
app.EnableBashCompletion = true
return app
}