diff --git a/README.md b/README.md index 36f948c..5d709f1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # cd-bookmark ## Synopsis -zsh plugin to bookmark directories to cd. +zsh and bash plugin to bookmark directories to cd. Inspired by [mokemokechicken post](http://qiita.com/mokemokechicken/items/69af0db3e2cd27c1c467) and shell script in the post. @@ -47,6 +47,12 @@ e.g. alias cdb='cd-bookmark' ``` +#### Bash +For bash users, put this in your shell initialization file (typically `$HOME/.bashrc`): +``` +source path/to/dir/cd-bookmark/cd-bookmark +``` + ## Usage diff --git a/cd-bookmark b/cd-bookmark old mode 100644 new mode 100755 index e0dd738..6cc5e30 --- a/cd-bookmark +++ b/cd-bookmark @@ -226,10 +226,29 @@ function _cdbookmark_main() { esac } +function _cdbookmarks_bash_completions() { + if [ "${#COMP_WORDS[@]}" = "2" ]; then + local word_list=(-a -c -d -l -e -p -h) + COMPREPLY=($(compgen -W "${word_list[*]}" -- "${COMP_WORDS[1]}")) + elif [ "${#COMP_WORDS[@]}" = "3" ] && [[ "${COMP_WORDS[1]}" =~ ^-[acdp]$ ]]; then + local word_list="$(_cdbookmark_list_bookmark_id)" + COMPREPLY=($(compgen -W "${word_list[*]}" -- "${COMP_WORDS[2]}")) + fi +} + #set -o xtrace #set -o verbose -_cdbookmark_main "$@" +if [ -n "$ZSH_VERSION" ]; then + # zsh entry point (executed as function from $(autoload -Uz)) + _cdbookmark_main "$@" +else + # bash entry point (executed as a sourced function) + function cd-bookmark() { + _cdbookmark_main "$@" + } + complete -F _cdbookmarks_bash_completions cd-bookmark +fi #set +o xtrace #set +o verbose