Skip to content

Commit

Permalink
Improve bash tab completion, fixes #162
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jun 8, 2018
1 parent 91a6b58 commit 8d72a41
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
4 changes: 4 additions & 0 deletions cmd/minify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Run the following command

and the `minify` command will be in your `$GOPATH/bin`.

You can enable bash tab completion by using

source minify_bash_tab_completion

## Usage
Usage: minify [options] [input]

Expand Down
16 changes: 0 additions & 16 deletions cmd/minify/minify-bash-completion.bash

This file was deleted.

29 changes: 29 additions & 0 deletions cmd/minify/minify_bash_tab_completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

_minify_complete()
{
local cur_word prev_word flags mimes types

cur_word="${COMP_WORDS[COMP_CWORD]}"
prev_word="${COMP_WORDS[COMP_CWORD-1]}"
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"
mimes="text/css text/html text/javascript application/json image/svg+xml text/xml"
types="css html js json svg xml"

if [[ ${cur_word} == -* ]] ; then
COMPREPLY=( $(compgen -W "${flags}" -- ${cur_word}) )
elif [[ ${prev_word} =~ ^--mime$ ]] ; then
COMPREPLY=( $(compgen -W "${mimes}" -- ${cur_word}) )
elif [[ ${prev_word} =~ ^--type$ ]] ; then
COMPREPLY=( $(compgen -W "${types}" -- ${cur_word}) )
elif [[ ${prev_word} =~ ^--(match|url|css-decimals|svg-decimals)$ ]] ; then
compopt +o default
COMPREPLY=()
else
compopt -o default
COMPREPLY=()
fi
return 0
}

complete -F _minify_complete minify

0 comments on commit 8d72a41

Please sign in to comment.