Skip to content

Commit

Permalink
ZSH USERS NOTE BACKWARD COMPATIBILITY WARNING!
Browse files Browse the repository at this point in the history
Test for compctl first, as bash will never have compctl, but zsh may
have complete, if bashcompinit was called. Since we're using this test
for prompt/precmd as well as completion, we want to run the right logic.
  • Loading branch information
rupa committed Sep 3, 2012
1 parent 9ac0898 commit b2d48e0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions z.sh
Expand Up @@ -177,17 +177,9 @@ alias ${_Z_CMD:-z}='_z 2>&1'

[ "$_Z_NO_RESOLVE_SYMLINKS" ] || _Z_RESOLVE_SYMLINKS="-P"

if complete &> /dev/null; then
# bash tab completion
complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z}
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list. avoid clobbering other PROMPT_COMMANDs.
echo $PROMPT_COMMAND | grep -q "_z --add"
[ $? -gt 0 ] && PROMPT_COMMAND='_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'"$PROMPT_COMMAND"
}
elif compctl &> /dev/null; then
if compctl &> /dev/null; then
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# populate directory list, avoid clobbering any other precmds
# zsh populate directory list, avoid clobbering any other precmds
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
_z_precmd() {
_z --add "${PWD:a}"
Expand All @@ -206,4 +198,12 @@ elif compctl &> /dev/null; then
reply=(${(f)"$(_z --complete "$compl")"})
}
compctl -U -K _z_zsh_tab_completion _z
elif complete &> /dev/null; then
# bash tab completion
complete -o filenames -C '_z --complete "$COMP_LINE"' ${_Z_CMD:-z}
[ "$_Z_NO_PROMPT_COMMAND" ] || {
# bash populate directory list. avoid clobbering other PROMPT_COMMANDs.
echo $PROMPT_COMMAND | grep -q "_z --add"
[ $? -gt 0 ] && PROMPT_COMMAND='_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'"$PROMPT_COMMAND"
}
fi

0 comments on commit b2d48e0

Please sign in to comment.