ohmyzsh / ohmyzsh

🙃 A delightful community-driven (with 2,400+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool that makes it easy to keep up with the latest updates from the community.
https://ohmyz.sh
MIT License
173.39k stars 25.88k forks source link

Zsh prints some script at startup, many functionality is "broken" #5710

Closed GRiMe2D closed 7 years ago

GRiMe2D commented 7 years ago
bracketed-paste-magic () {
    # undefined
    builtin autoload -XUz
}
colors () {
    emulate -L zsh
    typeset -Ag color colour
    color=(00 none 01 bold 02 faint 22 normal 03 standout 23 no-standout 04 underline 24 no-underline 05 blink 25 no-blink 07 reverse 27 no-reverse 08 conceal 28 no-conceal 30 black 40 bg-black 31 red 41 bg-red 32 green 42 bg-green 33 yellow 43 bg-yellow 34 blue 44 bg-blue 35 magenta 45 bg-magenta 36 cyan 46 bg-cyan 37 white 47 bg-white 39 default 49 bg-default) 
    local k
    for k in ${(k)color}
    do
        color[${color[$k]}]=$k 
    done
    for k in ${color[(I)3?]}
    do
        color[fg-${color[$k]}]=$k 
    done
    color[grey]=${color[black]} 
    color[fg-grey]=${color[grey]} 
    color[bg-grey]=${color[bg-black]} 
    colour=(${(kv)color}) 
    local lc=$'\e[' rc=m 
    typeset -Hg reset_color bold_color
    reset_color="$lc${color[none]}$rc" 
    bold_color="$lc${color[bold]}$rc" 
    typeset -AHg fg fg_bold fg_no_bold
    for k in ${(k)color[(I)fg-*]}
    do
        fg[${k#fg-}]="$lc${color[$k]}$rc" 
        fg_bold[${k#fg-}]="$lc${color[bold]};${color[$k]}$rc" 
        fg_no_bold[${k#fg-}]="$lc${color[normal]};${color[$k]}$rc" 
    done
    typeset -AHg bg bg_bold bg_no_bold
    for k in ${(k)color[(I)bg-*]}
    do
        bg[${k#bg-}]="$lc${color[$k]}$rc" 
        bg_bold[${k#bg-}]="$lc${color[bold]};${color[$k]}$rc" 
        bg_no_bold[${k#bg-}]="$lc${color[normal]};${color[$k]}$rc" 
    done
}
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 -gHA _comps _services _patcomps _postpatcomps
    typeset -gHA _compautos
    typeset -gHA _lastcomp
    if [[ -n $_i_dumpfile ]]
    then
        typeset -g _comp_dumpfile="$_i_dumpfile" 
    else
        typeset -g _comp_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump" 
    fi
    typeset -gHa _comp_options
    _comp_options=(bareglobqual extendedglob glob multibyte multifuncdef nullglob rcexpandparam unset NO_allexport NO_aliases NO_cshnullglob NO_cshjunkiequotes NO_errexit NO_globassign NO_globsubst NO_histsubstpattern NO_ignorebraces NO_ignoreclosebraces NO_kshglob NO_ksharrays NO_kshtypeset NO_markdirs NO_octalzeroes NO_posixbuiltins NO_shwordsplit NO_shglob NO_warncreateglobal) 
    typeset -gH _comp_setup='local -A _comp_caller_options;
             _comp_caller_options=(${(kv)options[@]});
             setopt localoptions localtraps localpatterns ${_comp_options[@]};
             local IFS=$'\'\ \\t\\r\\n\\0\'';
             builtin enable -p \| \~ \( \? \* \[ \< \^ \# 2>/dev/null;
             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" | IFS=$' \t' 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" | IFS=$' \t' 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
            IFS=$' \t' 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 
                IFS=$' \t' 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' | IFS=$' \t' 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
}
down-line-or-beginning-search () {
    # undefined
    builtin autoload -XU
}
edit-command-line () {
    # undefined
    builtin autoload -XU
}
is-at-least () {
    emulate -L zsh
    local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order 
    min_ver=(${=1}) 
    version=(${=2:-$ZSH_VERSION} 0) 
    while (( $min_cnt <= ${#min_ver} ))
    do
        while [[ "$part" != <-> ]]
        do
            (( ++ver_cnt > ${#version} )) && return 0
            if [[ ${version[ver_cnt]} = *[0-9][^0-9]* ]]
            then
                order=(${version[ver_cnt]} ${min_ver[ver_cnt]}) 
                if [[ ${version[ver_cnt]} = <->* ]]
                then
                    [[ $order != ${${(On)order}} ]] && return 1
                else
                    [[ $order != ${${(O)order}} ]] && return 1
                fi
                [[ $order[1] != $order[2] ]] && return 0
            fi
            part=${version[ver_cnt]##*[^0-9]} 
        done
        while true
        do
            (( ++min_cnt > ${#min_ver} )) && return 0
            [[ ${min_ver[min_cnt]} = <-> ]] && break
        done
        (( part > min_ver[min_cnt] )) && return 0
        (( part < min_ver[min_cnt] )) && return 1
        part='' 
    done
}
up-line-or-beginning-search () {
    # undefined
    builtin autoload -XU
}
url-quote-magic () {
    # undefined
    builtin autoload -XUz
}

This is what I see when Terminal launches

cd mv auto-compilation is broken, doesn't list files in current directory Tried to upgrade, no luck

.zshrc:

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH=/Users/GRiMe2D/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="agnoster"

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion. Case
# sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/rsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

System: OSX El Capitan 10.11.6 (15G31)

GRiMe2D commented 7 years ago

Updating zsh from brew somehow breaks this Need to run chsh again

Related https://github.com/robbyrussell/oh-my-zsh/issues/630

kakulukia commented 6 years ago

I currently have this problem and while it just occurred when starting zsh inside zsh. Removing and installing it again with brew made it worse so that now i always get tho script lines printed before the shell is ready. Everything works as far as i can tell, but its kinda annoying. What else beside reinstalling with brew can be done to maybe solve that problem?

mcornella commented 6 years ago

Run zsh -xvic 'exit' &>~/omz-debug.log and post the generated file as a private gist.

kakulukia commented 6 years ago

thx, but i got it solved with the help of some other threads, but good to have that command ready should that happen again :)

mcornella commented 6 years ago

What was the culprit?

IonCaza commented 6 years ago

@kakulukia what did you do to fix this?

IonCaza commented 6 years ago

Try chsh -s /bin/zsh - in my instance, I was running a different version of zsh, not the one inside /bin/zsh

kakulukia commented 6 years ago

What was the culprit?

If only i knew, but this fixed it:

compaudit | sudo xargs chmod g-w
compaudit | sudo xargs chown root
sudo rm ~/.zcompdump*
compinit
sultanahamer commented 6 years ago

I have the same issue.

I have laptop with limited privileges, Also I am behind proxy. I have run installation command with wget and everything went well except the famouse error of permissions for directories and asked me to skip with a variable set to true in zshrc. After setting that variable and reopening iterm2, I now the this issue listed being poured into terminal and no auto completion working.

Right now, I have added clear right after source command in zshrc. Also am using compinit then 'y' to start autocomplete in iterm.

brenthaertlein commented 6 years ago

This happened to me when root owned the ~/.oh-my-zsh folder (my bad).

I did sudo chown -R $(whoami) ~/.oh-my-zsh and then source .zshrc, which fixed the issue. No source code printed from source $ZSH/oh-my-zsh.sh in the .zshrc file and autocomplete now works.