From b2d48e0a683bc9cc896eecfb52bc30904359a5eb Mon Sep 17 00:00:00 2001 From: rupa Date: Mon, 3 Sep 2012 18:07:37 -0400 Subject: [PATCH] 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. --- z.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/z.sh b/z.sh index 38cc1fd..4d903cd 100755 --- a/z.sh +++ b/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} +if compctl &> /dev/null; then [ "$_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 - [ "$_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