Improve bash tab completion, fixes #162
Taco de Wolff
5 years ago
11 | 11 |
go get github.com/tdewolff/minify/cmd/minify
|
12 | 12 |
|
13 | 13 |
and the `minify` command will be in your `$GOPATH/bin`.
|
|
14 |
|
|
15 |
You can enable bash tab completion by using
|
|
16 |
|
|
17 |
source minify_bash_tab_completion
|
14 | 18 |
|
15 | 19 |
## Usage
|
16 | 20 |
Usage: minify [options] [input]
|
cmd/minify/minify-bash-completion.bash
less
more
0 | |
_minify_complete()
|
1 | |
{
|
2 | |
local cur_work flags
|
3 | |
|
4 | |
cur_word="${COMP_WORDS[COMP_CWORD]}"
|
5 | |
flags="-a --all -l --list --match --mime -o --output -r --recursive --type --url -v --verbose --version -w --watch --css-decimals --html-keep-conditional-comments --html-keep-default-attrvals --html-keep-document-tags --html-keep-end-tags --html-keep-whitespace --svg-decimals --xml-keep-whitespace"
|
6 | |
|
7 | |
if [[ ${cur_word} == -* ]] ; then
|
8 | |
COMPREPLY=( $(compgen -W "${flags}" -- ${cur_word}) )
|
9 | |
else
|
10 | |
COMPREPLY=()
|
11 | |
fi
|
12 | |
return 0
|
13 | |
}
|
14 | |
|
15 | |
complete -F _minify_complete minify
|
|
0 |
#!/bin/bash
|
|
1 |
|
|
2 |
_minify_complete()
|
|
3 |
{
|
|
4 |
local cur_word prev_word flags mimes types
|
|
5 |
|
|
6 |
cur_word="${COMP_WORDS[COMP_CWORD]}"
|
|
7 |
prev_word="${COMP_WORDS[COMP_CWORD-1]}"
|
|
8 |
flags="-a --all -l --list --match --mime -o --output -r --recursive --type --url -v --verbose --version -w --watch --css-decimals --html-keep-conditional-comments --html-keep-default-attrvals --html-keep-document-tags --html-keep-end-tags --html-keep-whitespace --svg-decimals --xml-keep-whitespace"
|
|
9 |
mimes="text/css text/html text/javascript application/json image/svg+xml text/xml"
|
|
10 |
types="css html js json svg xml"
|
|
11 |
|
|
12 |
if [[ ${cur_word} == -* ]] ; then
|
|
13 |
COMPREPLY=( $(compgen -W "${flags}" -- ${cur_word}) )
|
|
14 |
elif [[ ${prev_word} =~ ^--mime$ ]] ; then
|
|
15 |
COMPREPLY=( $(compgen -W "${mimes}" -- ${cur_word}) )
|
|
16 |
elif [[ ${prev_word} =~ ^--type$ ]] ; then
|
|
17 |
COMPREPLY=( $(compgen -W "${types}" -- ${cur_word}) )
|
|
18 |
elif [[ ${prev_word} =~ ^--(match|url|css-decimals|svg-decimals)$ ]] ; then
|
|
19 |
compopt +o default
|
|
20 |
COMPREPLY=()
|
|
21 |
else
|
|
22 |
compopt -o default
|
|
23 |
COMPREPLY=()
|
|
24 |
fi
|
|
25 |
return 0
|
|
26 |
}
|
|
27 |
|
|
28 |
complete -F _minify_complete minify
|