From 68624c7acb2daa5ef6ff97f9c629b3330114d9af Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 21 Apr 2019 21:24:50 -0400 Subject: [PATCH] Add bash completion to shovel --- completions/README.md | 19 +++++++++++++++++++ completions/bash/shovel | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 completions/bash/shovel diff --git a/completions/README.md b/completions/README.md index dff59a0..89a7d25 100644 --- a/completions/README.md +++ b/completions/README.md @@ -13,3 +13,22 @@ In the `completions/zsh` directory is a file to help with auto-completions in 2. Navigate to a directory where you've tasks in `shovel.py` or under `shovel/`, and hit `TAB` twice. Or, type the first couple letters of a command and hit `TAB` once. Boom. + +Bash +---- +In the `completions/bash` directory is a file to help with auto-completions in `bash`. Installation: + +1. Install [bash-completion](https://github.com/scop/bash-completion) if you haven't already. + `brew install bash-completion@2` + +2. Copy `completions/bash/shovel` to your local bash completions directory. + +``` +mkdir -p ~/.local/share/bash-completion/completions + +cp completions/bash/shovel ~/.local/share/bash-completion/completions/shovel +``` + +3. Open a new terminal so the completions file will be sourced. + +4. Navigate to a directory where tasks are in `shovel.py` or `shovel/` and hit `TAB` twice. Or type the first couple letters of a command and hit `TAB` once. Baam! diff --git a/completions/bash/shovel b/completions/bash/shovel new file mode 100644 index 0000000..4f5b030 --- /dev/null +++ b/completions/bash/shovel @@ -0,0 +1,22 @@ +# shovel completion + +_shovel() +{ + local cur prev words cword + _init_completion || return + + case $prev in + --help|--version|-!(-*)[h]) + return + ;; + esac + + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W '$( _parse_help "$1" --help )' -- "$cur" ) ) + elif [[ -f shovel.py || -d shovel ]]; then + COMPREPLY=( $( compgen -W '$(shovel tasks | cut -s -d"#" -f1) help tasks' -- "$cur") ) + fi +} && +complete -F _shovel shovel + +# ex: filetype=sh