diff --git a/README.MD b/README.MD index 947e346..9d59b3b 100644 --- a/README.MD +++ b/README.MD @@ -12,6 +12,16 @@ Wilfred is a simple [boilerplate](https://en.wikipedia.org/wiki/Boilerplate_code `npm install -g wilfred` +**Optional:** + +To use autocompletion on Wilfred, add the following lines to your ~/.bash_profile or ~/.zshrc. + +```bash +if [ -f $(npm root -g)/wilfred/autocomplete/wilfred-completion.bash ]; then + . $(npm root -g)/wilfred/autocomplete/wilfred-completion.bash +fi +``` + ## Usage For more information on how to use wilfred run `wilfred --help` @@ -21,11 +31,10 @@ For more information on how to use wilfred run `wilfred --help` - [x] Local folders - [x] Interactive and non-interactive mode[1](#footnote1) - [x] `.wilfredhook` for running commands after copy +- [x] Bash autocomplete - [ ] GitHub support - [ ] `.wilfredignore` for files to ignore during copy (maybe?) -- [ ] Bash autocomplete -1: If you pass in the boilerplate name as argument it will run non-interactive. If you don't it will run in interactive mode. ## Changelog diff --git a/autocomplete/wilfred-completion.bash b/autocomplete/wilfred-completion.bash new file mode 100755 index 0000000..dfffc7b --- /dev/null +++ b/autocomplete/wilfred-completion.bash @@ -0,0 +1,31 @@ +#!/bin/bash + +# bash/zsh provider completion support for wilfred +# +# Usage: +# +# 1. Have wilfred installed and do `npm install -g root`. +# 2. Add the following lines to .bash_profile or .zshrc +# +# if [ -f $(npm root -g)/wilfred/autocomplete/wilfred-completion.bash ]; then +# . $(npm root -g)/wilfred/autocomplete/wilfred-completion.bash +# fi + +if [[ -n ${ZSH_VERSION-} ]]; then + autoload -U +X compinit && compinit + autoload -U +X bashcompinit && bashcompinit +fi + +_wilfred_completion() +{ + local cur=${COMP_WORDS[COMP_CWORD]} + local prev=${COMP_WORDS[COMP_CWORD-1]} + local IFS=$'\n' + + if [[ "$prev" == "wilfred" ]]; then + # Get all boilerplates using `wilfred -l` + COMPREPLY=( $(compgen -W "$(wilfred -l | awk '{print $1;}')" -- $cur) ) + fi + +} +complete -o filenames -F _wilfred_completion wilfred \ No newline at end of file