Skip to content

Loading…

Fix loading issue under ZSH #65

Closed
wants to merge 1 commit into from

2 participants

@jimeh

I'm not sure this is something related specifically to my setup, but here goes.

As far as I know ZSH tries to be Bash-compatible by among other things, letting Bash completion work via the complete command. Hence checking for it before compctl under ZSH will always make it think it's running under Bash.

This fix simply checks for ZSH's compctl first, which Bash does not have, and hence works correctly under both Bash and ZSH.

@jimeh jimeh Fix loading issue under ZSH
I'm not sure this is something related specifically to my setup, but
here goes.

As far as I know ZSH tries to be Bash-compatible by among other things,
letting Bash completion work via the `complete` command. Hence checking
for it before `compctl` under ZSH will always make it think it's running
under Bash.

This fix simply checks for ZSH's `compctl` first, which Bash does not
have, and hence works correctly under both Bash and ZSH.
03b37b0
@rupa
Owner

I think it is your setup:


~$ complete
zsh: command not found: complete

I wonder where your zsh got a complete command. What does which complete or type complete tell you?

I guess I wouldn't mind switching the order - if I do, I'll probably not use this pull request tho, simply cause I want to keep the zsh compatibility warning in the first line of commits for a while longer ...

@jimeh

After a little bit of research I've found an explenation on the zshcompsys man page:

The function bashcompinit compatibility with bash’s programmable completion system. When run it will define the functions, compgen and complete which correspond to the bash builtins with the same names. It will then be possible to use completion specifications and functions written for bash.

As far as I know there's nothing in my setup that calls bashcompinit. But it seems as if in ZSH 5.x bashcompinit is run by default. Or at least since April last year by the look of this patch: http://www.spinics.net/lists/git/msg156326.html

I don't mind if you don't use my specific commit, for the time being I have my dotfiles using my own fork :)

And lastly, here's the output for the commands you asked about:

jimeh@air ~$ zsh --version
zsh 5.0.0 (x86_64-apple-darwin12.0.0)
jimeh@air ~$ complete
jimeh@air ~$ type complete
complete is a shell function
jimeh@air ~$ which complete
complete () {
        emulate -L zsh
        local args void cmd print remove
        args=("$@") 
        zparseopts -D -a void o: A: G: W: C: F: P: S: X: a b c d e f g j k u v p=print r=remove
        if [[ -n $print ]]
        then
                printf 'complete %2$s %1$s\n' "${(@kv)_comps[(R)_bash*]#* }"
        elif [[ -n $remove ]]
        then
                for cmd
                do
                        unset "_comps[$cmd]"
                done
        else
                compdef _bash_complete\ ${(j. .)${(q)args[1,-1-$#]}} "$@"
        fi
}
@rupa
Owner

Thanks, I made this change.

@rupa rupa closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 2, 2012
  1. @jimeh

    Fix loading issue under ZSH

    jimeh committed
    I'm not sure this is something related specifically to my setup, but
    here goes.
    
    As far as I know ZSH tries to be Bash-compatible by among other things,
    letting Bash completion work via the `complete` command. Hence checking
    for it before `compctl` under ZSH will always make it think it's running
    under Bash.
    
    This fix simply checks for ZSH's `compctl` first, which Bash does not
    have, and hence works correctly under both Bash and ZSH.
Showing with 10 additions and 10 deletions.
  1. +10 −10 z.sh
View
20 z.sh
@@ -177,15 +177,7 @@ 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
if [ "$_Z_NO_RESOLVE_SYMLINKS" ]; then
@@ -206,4 +198,12 @@ elif compctl &> /dev/null; then
reply=(${(f)"$(_z --complete "$compl")"})
}
compctl -U -K _z_zsh_tab_completion _z
-fi
+elif 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"
+ }
+fi
Something went wrong with that request. Please try again.