Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 35 additions & 1 deletion cd-bookmark
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,44 @@ 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 comp_word="${COMP_WORDS[2]}"

if [[ "${COMP_WORDS[1]}" = -c ]] && [[ "$comp_word" == */* ]]; then
local strip_bookmark_id="${comp_word%%/*}"
local dir_path="${comp_word#*/}"
local bookmark_dir="$(_cdbookmark_get_bookmark $strip_bookmark_id)"

if [ -n "$bookmark_dir" ]; then
bookmark_dir="${bookmark_dir}/${dir_path}"
local word_list=$(ls -d "${bookmark_dir}"*/ 2>/dev/null | \
sed -e "s|${bookmark_dir}||" -e 's|/$||' -e "s|^|${comp_word}|")
COMPREPLY=($(compgen -W "${word_list[*]}" -- "${comp_word}"))
fi
else
local word_list="$(_cdbookmark_list_bookmark_id)"
COMPREPLY=($(compgen -W "${word_list[*]}" -- "${comp_word}"))
fi
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