【问题标题】:How to make oh-my-zsh use the latest zsh version?如何让 oh-my-zsh 使用最新的 zsh 版本?
【发布时间】:2013-10-09 19:00:08
【问题描述】:

我在 iTerm (OS X) 中使用 zsh 和 oh-my-zsh。我遇到以下问题:

  1. echo $ZSH_VERSION 返回 4.3.11。
  2. 我成功运行upgrade_oh_my_zsh
  3. echo $ZSH_VERSION 再次返回 4.3.11。
  4. 我运行brew install zsh / brew upgrade zsh 得到Error: zsh-5.0.2 already installed
  5. 然而,即使在我重新启动 iTerm echo $ZSH_VERSION 后仍返回 4.3.11。

如何让 OMZ 使用最新的 zsh 版本?

【问题讨论】:

    标签: zsh oh-my-zsh


    【解决方案1】:

    我的 ~/.zshrc 中有以下内容。它将在给定的目录列表中找到一个可用的 zsh,按版本号对其进行排序并执行最新的。

    if [[ $- == *i* ]]; then
        arg=$(
            for dir in \
                /usr/local/bin \
                /usr/gnu/bin \
                /usr/sfw/bin \
                /bin \
                /usr/bin
            do
                arg=$dir/zsh
    
                # Make sure the shell is a readable, executable file.
                if [[ ! -f $arg || ! -r $arg || ! -x $arg ]]; then
                    continue
                fi
    
                # Print sortable version number and path to shell.
                ver=$( $arg -c 'echo $ZSH_VERSION' 2>/dev/null )
                if [[ -n $ver ]]; then
                    printf '%03u%03u%03u %s\n' $( echo $ver | tr '.' ' ' ) $arg
                fi
            done | sort -r | head -1 | cut -c11-
        )
    
        if [[ -n $arg && $arg != $SHELL ]]; then
            echo "Switching SHELL to $arg"
            export SHELL=$arg
            exec $SHELL -li
        fi
    fi
    

    如果你想让它搜索PATH变量的内容,你可以使用

    for dir in $( echo "$PATH" | tr ':' ' ' ); do
        (...)
    

    如果目录名称中有空格,则必须使用类似

    printf '%s\n' "$PATH" | tr ':' '\n' | while read dir; do
        (...)
    

    并在 $arg 和 $SHELL 某些地方添加双引号。

    【讨论】:

      【解决方案2】:

      很高兴您找到了解决方案。一些注意事项:

      1. oh-my-zsh 是一个 zsh 配置框架。它不是“zsh”,只是 shell 的配置文件。升级oh-my-zshzsh 本身是两个独立的、基本上不相关的任务。
      2. 用新的二进制文件覆盖/bin/zsh 是一种解决方案。另一种方法是使用symlink - 可能从/usr/local/Cellar/zsh/5.0.2/bin/zsh-5.2.0$PATH 的某个位置(如/usr/local/bin/),并使用chsh 设置shell。符号链接的优点是您保留了所有二进制文件(因此您仍然拥有4.35.05.2)。
      3. This question 可能会解释为什么 chsh 不起作用。

      【讨论】:

        【解决方案3】:

        解决了这个问题。我的/etc/paths 已经在顶部有/usr/local/bin。当我打开/usr/local/bin/时,我看到除了zsh,我还有zsh-5.2.0。我试过chsh -s /usr/local/bin/zsh-5.2.0 但这没有帮助。我删除了zsh 并将zsh-5.2.0 重命名为zsh -> 也无济于事。我看到zsh-5.2.0 指向/usr/local/Cellar/zsh/5.0.2/bin/zsh-5.0.2,之前我看到原来的zsh 指向/bin/zsh。所以对我有帮助的是:

        • 打开/usr/local/Cellar/zsh/5.0.2/bin/ -> 包含zshzsh-5.2.0
        • zsh从那里复制到/bin/并覆盖/bin/zsh
        • 重启 iTerm

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-12-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-01-27
          相关资源
          最近更新 更多