Skip to content

Commit

Permalink
Add minimal bash support with completion
Browse files Browse the repository at this point in the history
Bash users should add to their .bashrc:
source path/to/dir/cd-bookmark/cd-bookmark

Reference for completion implementation:
https://opensource.com/article/18/3/creating-bash-completion-script

Fixes #6
  • Loading branch information
erikw committed Nov 4, 2021
1 parent f5943f0 commit fc9c5c7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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


Expand Down
21 changes: 20 additions & 1 deletion cd-bookmark
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fc9c5c7

Please sign in to comment.