Skip to content

compdef: unknown command or service: git #630

@mikebell

Description

@mikebell

zsh 4.3.12
lastest clone of oh-my-zsh

After manually installing it (not using the wget method) whenever I login I get a load of code outputted to iterm2.

compdump () {
    # undefined
    builtin autoload -XUz
}
compinit () {
    emulate -L zsh
    setopt extendedglob
    typeset _i_dumpfile _i_files _i_line _i_done _i_dir _i_autodump=1
    typeset _i_tag _i_file _i_addfiles _i_fail=ask _i_check=yes _i_name
    while [[ $# -gt 0 && $1 = -[dDiuC] ]]
    do
        case "$1" in
            (-d) _i_autodump=1 
                shift
                if [[ $# -gt 0 && "$1" != -[dfQC] ]]
                then
                    _i_dumpfile="$1" 
                    shift
                fi ;;
            (-D) _i_autodump=0 
                shift ;;
            (-i) _i_fail=ign 
                shift ;;
            (-u) _i_fail=use 
                shift ;;
            (-C) _i_check= 
                shift ;;
        esac
    done
    typeset -gA _comps _services _patcomps _postpatcomps
    typeset -gA _compautos
    typeset -gA _lastcomp
    if [[ -n $_i_dumpfile ]]
    then
        typeset -g _comp_dumpfile="$_i_dumpfile"
    else
        typeset -g _comp_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump"
    fi
    typeset -ga _comp_options
    _comp_options=(bareglobqual extendedglob glob multibyte nullglob rcexpandparam unset NO_allexport NO_aliases NO_cshnullglob NO_cshjunkiequotes NO_errexit NO_globsubst NO_histsubstpattern NO_ignorebraces NO_kshglob NO_ksharrays NO_kshtypeset NO_markdirs NO_octalzeroes NO_shwordsplit NO_shglob NO_warncreateglobal) 
    typeset -g _comp_setup='local -A _comp_caller_options;
             _comp_caller_options=(${(kv)options});
             setopt localoptions localtraps ${_comp_options[@]};
             local IFS=$'\'\ \\t\\r\\n\\0\''
             exec </dev/null;
             trap - ZERR
             local -a reply
             local REPLY'
    typeset -ga compprefuncs comppostfuncs
    compprefuncs=() 
    comppostfuncs=() 
    : $funcstack
    compdef () {
        local opt autol type func delete eval new i ret=0 cmd svc
        local -a match mbegin mend
        emulate -L zsh
        setopt extendedglob
        if (( ! $# ))
        then
            print -u2 "$0: I need arguments"
            return 1
        fi
        while getopts "anpPkKde" opt
        do
            case "$opt" in
                (a) autol=yes  ;;
                (n) new=yes  ;;
                ([pPkK]) if [[ -n "$type" ]]
                    then
                        print -u2 "$0: type already set to $type"
                        return 1
                    fi
                    if [[ "$opt" = p ]]
                    then
                        type=pattern 
                    elif [[ "$opt" = P ]]
                    then
                        type=postpattern 
                    elif [[ "$opt" = K ]]
                    then
                        type=widgetkey 
                    else
                        type=key 
                    fi ;;
                (d) delete=yes  ;;
                (e) eval=yes  ;;
            esac
        done
        shift OPTIND-1
        if (( ! $# ))
        then
            print -u2 "$0: I need arguments"
            return 1
        fi
        if [[ -z "$delete" ]]
        then
            if [[ -z "$eval" ]] && [[ "$1" = *\=* ]]
            then
                while (( $# ))
                do
                    if [[ "$1" = *\=* ]]
                    then
                        cmd="${1%%\=*}" 
                        svc="${1#*\=}" 
                        func="$_comps[${_services[(r)$svc]:-$svc}]" 
                        [[ -n ${_services[$svc]} ]] && svc=${_services[$svc]} 
                        [[ -z "$func" ]] && func="${${_patcomps[(K)$svc][1]}:-${_postpatcomps[(K)$svc][1]}}" 
                        if [[ -n "$func" ]]
                        then
                            _comps[$cmd]="$func" 
                            _services[$cmd]="$svc" 
                        else
                            print -u2 "$0: unknown command or service: $svc"
                            ret=1 
                        fi
                    else
                        print -u2 "$0: invalid argument: $1"
                        ret=1 
                    fi
                    shift
                done
                return ret
            fi
            func="$1" 
            [[ -n "$autol" ]] && autoload -Uz "$func"
            shift
            case "$type" in
                (widgetkey) while [[ -n $1 ]]
                    do
                        if [[ $# -lt 3 ]]
                        then
                            print -u2 "$0: compdef -K requires <widget> <comp-widget> <key>"
                            return 1
                        fi
                        [[ $1 = _* ]] || 1="_$1" 
                        [[ $2 = .* ]] || 2=".$2" 
                        [[ $2 = .menu-select ]] && zmodload -i zsh/complist
                        zle -C "$1" "$2" "$func"
                        if [[ -n $new ]]
                        then
                            bindkey "$3" | read -A opt
                            [[ $opt[-1] = undefined-key ]] && bindkey "$3" "$1"
                        else
                            bindkey "$3" "$1"
                        fi
                        shift 3
                    done ;;
                (key) if [[ $# -lt 2 ]]
                    then
                        print -u2 "$0: missing keys"
                        return 1
                    fi
                    if [[ $1 = .* ]]
                    then
                        [[ $1 = .menu-select ]] && zmodload -i zsh/complist
                        zle -C "$func" "$1" "$func"
                    else
                        [[ $1 = menu-select ]] && zmodload -i zsh/complist
                        zle -C "$func" ".$1" "$func"
                    fi
                    shift
                    for i
                    do
                        if [[ -n $new ]]
                        then
                            bindkey "$i" | read -A opt
                            [[ $opt[-1] = undefined-key ]] || continue
                        fi
                        bindkey "$i" "$func"
                    done ;;
                (*) while (( $# ))
                    do
                        if [[ "$1" = -N ]]
                        then
                            type=normal 
                        elif [[ "$1" = -p ]]
                        then
                            type=pattern 
                        elif [[ "$1" = -P ]]
                        then
                            type=postpattern 
                        else
                            case "$type" in
                                (pattern) if [[ $1 = (#b)(*)=(*) ]]
                                    then
                                        _patcomps[$match[1]]="=$match[2]=$func" 
                                    else
                                        _patcomps[$1]="$func" 
                                    fi ;;
                                (postpattern) if [[ $1 = (#b)(*)=(*) ]]
                                    then
                                        _postpatcomps[$match[1]]="=$match[2]=$func" 
                                    else
                                        _postpatcomps[$1]="$func" 
                                    fi ;;
                                (*) if [[ "$1" = *\=* ]]
                                    then
                                        cmd="${1%%\=*}" 
                                        svc=yes 
                                    else
                                        cmd="$1" 
                                        svc= 
                                    fi
                                    if [[ -z "$new" || -z "${_comps[$1]}" ]]
                                    then
                                        _comps[$cmd]="$func" 
                                        [[ -n "$svc" ]] && _services[$cmd]="${1#*\=}" 
                                    fi ;;
                            esac
                        fi
                        shift
                    done ;;
            esac
        else
            case "$type" in
                (pattern) unset "_patcomps[$^@]" ;;
                (postpattern) unset "_postpatcomps[$^@]" ;;
                (key) print -u2 "$0: cannot restore key bindings"
                    return 1 ;;
                (*) unset "_comps[$^@]" ;;
            esac
        fi
    }
    typeset _i_wdirs _i_wfiles
    _i_wdirs=() 
    _i_wfiles=() 
    autoload -Uz compaudit
    if [[ -n "$_i_check" ]]
    then
        typeset _i_q
        if ! eval compaudit
        then
            if [[ -n "$_i_q" ]]
            then
                if [[ "$_i_fail" = ask ]]
                then
                    if ! read -q "?zsh compinit: insecure $_i_q, run compaudit for list.
Ignore insecure $_i_q and continue [y] or abort compinit [n]? "
                    then
                        print -u2 "$0: initialization aborted"
                        unfunction compinit compdef
                        unset _comp_dumpfile _comp_secure compprefuncs comppostfuncs _comps _patcomps _postpatcomps _compautos _lastcomp
                        return 1
                    fi
                    _i_wfiles=() 
                    _i_wdirs=() 
                else
                    (( $#_i_wfiles )) && _i_files=("${(@)_i_files:#(${(j:|:)_i_wfiles%.zwc})}") 
                    (( $#_i_wdirs )) && _i_files=("${(@)_i_files:#(${(j:|:)_i_wdirs%.zwc})/*}") 
                fi
            fi
            typeset -g _comp_secure=yes
        fi
    fi
    autoload -Uz compdump compinstall
    _i_done='' 
    if [[ -f "$_comp_dumpfile" ]]
    then
        if [[ -n "$_i_check" ]]
        then
            read -rA _i_line < "$_comp_dumpfile"
            if [[ _i_autodump -eq 1 && $_i_line[2] -eq $#_i_files && $ZSH_VERSION = $_i_line[4] ]]
            then
                builtin . "$_comp_dumpfile"
                _i_done=yes 
            fi
        else
            builtin . "$_comp_dumpfile"
            _i_done=yes 
        fi
    fi
    if [[ -z "$_i_done" ]]
    then
        typeset -A _i_test
        for _i_dir in $fpath
        do
            [[ $_i_dir = . ]] && continue
            (( $_i_wdirs[(I)$_i_dir] )) && continue
            for _i_file in $_i_dir/^([^_]*|*~|*.zwc)(N)
            do
                _i_name="${_i_file:t}" 
                (( $+_i_test[$_i_name] + $_i_wfiles[(I)$_i_file] )) && continue
                _i_test[$_i_name]=yes 
                read -rA _i_line < $_i_file
                _i_tag=$_i_line[1] 
                shift _i_line
                case $_i_tag in
                    (\#compdef) if [[ $_i_line[1] = -[pPkK](n|) ]]
                        then
                            compdef ${_i_line[1]}na "${_i_name}" "${(@)_i_line[2,-1]}"
                        else
                            compdef -na "${_i_name}" "${_i_line[@]}"
                        fi ;;
                    (\#autoload) autoload -Uz "$_i_line[@]" ${_i_name}
                        [[ "$_i_line" != \ # ]] && _compautos[${_i_name}]="$_i_line"  ;;
                esac
            done
        done
        if [[ $_i_autodump = 1 ]]
        then
            compdump
        fi
    fi
    for _i_line in complete-word delete-char-or-list expand-or-complete expand-or-complete-prefix list-choices menu-complete menu-expand-or-complete reverse-menu-complete
    do
        zle -C $_i_line .$_i_line _main_complete
    done
    zle -la menu-select && zle -C menu-select .menu-select _main_complete
    bindkey '^i' | read -A _i_line
    if [[ ${_i_line[2]} = expand-or-complete ]] && zstyle -a ':completion:' completer _i_line && (( ${_i_line[(i)_expand]} <= ${#_i_line} ))
    then
        bindkey '^i' complete-word
    fi
    unfunction compinit compaudit
    autoload -Uz compinit compaudit
    return 0
}
compinstall () {
    # undefined
    builtin autoload -XUz
}
edit-command-line () {
    # undefined
    builtin autoload -XU
}
url-quote-magic () {
    # undefined
    builtin autoload -XU
}
compdef: unknown command or service: git
compdef: unknown command or service: git
compdef: unknown command or service: git
compdef: unknown command or service: git
compdef: unknown command or service: git
compdef: unknown command or service: git

Tab complete doesn't work, the git plugin seems to be working and themes are also working. This is my 5th install of oh-my-zsh and I've not seen this issue before.

Activity

gwjo

gwjo commented on Sep 28, 2011

@gwjo
Contributor

The compdef error is the same one as in #399, but that was caused by an older version of zsh that didn't have the git completions.

BigForNothing

BigForNothing commented on Oct 17, 2011

@BigForNothing

Try running this and see if it fixes it for you:

compaudit | xargs chmod g-w

It did for me.

theckman

theckman commented on Nov 26, 2011

@theckman

I'm having the same issue as well. The above recommendation had no change as compaudit did not print out any lines.

Any other theories?

theckman

theckman commented on Nov 28, 2011

@theckman

Here's a bit more info about the system I am currently using:

Mac OS X 10.5.8
zsh 4.3.4 (i386-apple-darwin9.0)
iTerm2 Build 1.0.0.20111020

borisbrodski

borisbrodski commented on Jan 5, 2012

@borisbrodski

Confirm that on N900 Maemo:

$ uname -a
Linux Nokia-N900 2.6.28.10-power49 #1 PREEMPT Fri Nov 18 23:59:53 EET 2011 armv7l unknown

$ zsh -v
zsh 4.3.10 (arm-unknown-linux-gnu)

theckman

theckman commented on Jan 5, 2012

@theckman

I figured out the problem I was experiencing. I had installed zsh view homebrew on OS X. In the process of moving to ZSH I didn't realize my path got whacked out and it was using the Apple-supplied version of ZSH and not the one I had built.

Fix path, re-chsh, happiness ensued.

gdelfino

gdelfino commented on Feb 8, 2012

@gdelfino

I am having these same issue. I am using zsh 4.3.15 installed in /usr/local/bin/zsh and git 1.7.3.2

This is on a Centos 5.7 machine and the problem happens with regular users but not with the root user.

Curiously I have an identical install on a Centos 6 machine that worked just fine.

theckman

theckman commented on Feb 8, 2012

@theckman

You can't really call two similar CentOS 5.7 and 6.X installs identical. Also, are you sure that your non-root users are using the zsh 4.3.15 installed in /usr/local/bin/zsh? There are three commands you can run to verify:

echo $SHELL
which zsh
zsh --version

I had an issue where I thought I had the right version installed, but the way my paths where I was using the system installed version of ZSH, and not the one I had installed.

wishi

wishi commented on Feb 16, 2012

@wishi

I have the same problem with Arch Linux
zsh 4.3.15

compaudit | xargs chmod g-w
zsh: command not found: compaudit
chmod: missing operand after `g-w'

j16r

j16r commented on Apr 10, 2012

@j16r
Contributor

I'm seeing this problem also, when running up to date zsh:

zsh 4.3.17 (x86_64-apple-darwin11.3.0)
Darwin ix.local 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64
theckman

theckman commented on Apr 10, 2012

@theckman

@excepttheweasel what does echo $SHELL give you? What version do you get when running that executable?

j16r

j16r commented on Apr 10, 2012

@j16r
Contributor

echo $SHELL =>

/usr/local/bin/zsh

Which is version 4.3.17 as posted above, provided by homebrew.

theckman

theckman commented on Apr 10, 2012

@theckman

Seems we are running identical configurations. Mine just seemed to work out of the box when I set up homebrew and oh-my-zsh on my Air.

funnell

funnell commented on Oct 10, 2012

@funnell

I'm also having this problem on one of the linux servers I'm using. It works on a different linux server and two different Apple computers. I'm also using the version that I compiled (5.0.0).

87 remaining items

aryehbeitz

aryehbeitz commented on Feb 28, 2018

@aryehbeitz

I ran zsh -xv &> >(tee ~/omz-debug.log 2>/dev/null) and searched for the text of the errors I received

For this error:

complete:13: command not found: compdef

I fixed it in the file ~/.nvm/bash_completion on line 96, i commented out this line
complete -o default -F __nvm nvm

For this error:

__rvm_cleanse_variables: function definition file not found
command not found: rvm_error

I had to comment out a few lines around .rvm/scripts/initialize

__rvm_cleanse_variables ||
if [[ -n "${ZSH_VERSION:-}" ]]
then rvm_error "ZSH Error, run \`rm -f ~/.zcompdump\` and try again."
fi
278kunal

278kunal commented on May 6, 2018

@278kunal

@nnadboralski-zz Thanks Bro !! You made my day.

raguay

raguay commented on May 8, 2019

@raguay

I just got this error on today's update:

~/.oh-my-zsh/lib/directories.zsh:32: command not found: compdef

mcornella

mcornella commented on May 8, 2019

@mcornella
Member

Run upgrade_oh_my_zsh for a fix.

raguay

raguay commented on May 8, 2019

@raguay
worc

worc commented on Feb 6, 2020

@worc

upgrade_oh_my_zsh doesn't fix it

mcornella

mcornella commented on Feb 6, 2020

@mcornella
Member

Try rm $ZSH_COMPDUMP, then exec zsh. See the wiki FAQ for details.

worc

worc commented on Feb 7, 2020

@worc

removing the compdump also didn't work, but it looks like it was a syntax error in my .zshrc file.

i had my plugins listed as a comma separated list:

plugins=(git, docker)

and the error message was exactly correct, with the dangling comma:

[oh-my-zsh] plugin 'git,' not found

removing the comma fixes the error. hopefully that's helpful for someone else out there. it's one of those typos that's hard to see to begin with, and harder to recognize when you spend most of your day working in scripts or languages where a space delineated list would be the error.

BallisticPain

BallisticPain commented on Jul 24, 2020

@BallisticPain

So I ran through all of the fixes and none of them worked for me... my error was slightly different. It wasn't from a complete function call but an eval call...
(eval):6: command not found: compdef

So after trying everything else, I started looking into my ~/.zshrc file for any eval commands. I noticed that oh-my-zsh had put all eval type commands at the bottom of the file wrapped in if statements to ensure the command existed (which mine do/did exist, but can't be too careful).

I found two that were being called before oh-my-zsh was being initialized and decided to move those to the bottom of the file. After moving them and wrapping them in if statements for future proofing my configuration these are the two I moved...

if command -v thefuck 1>/dev/null 2>&1; then
    eval $(thefuck --alias)
fi

if command -v pipenv 1>/dev/null 2>&1; then
    eval "$(pipenv --completion)"
fi

It is possible only one of these was causing the issue, but I moved all eval related statements to the bottom of my ~/.zshrc file.

I hope this helps someone and saves some time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @robbyrussell@gdelfino@BigForNothing@amiorin@wishi

      Issue actions

        compdef: unknown command or service: git · Issue #630 · ohmyzsh/ohmyzsh