Permalink
Browse files

ZSH USERS NOTE BACKWARD COMPATIBILITY WARNING!

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...
1 parent 9ac0898 commit b2d48e0a683bc9cc896eecfb52bc30904359a5eb @rupa committed Sep 3, 2012
Showing with 10 additions and 10 deletions.
  1. +10 −10 z.sh
View
20 z.sh
@@ -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}"
@@ -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.