【问题标题】:Is there any way to get iTerm2 to color each new tab with a different color (using Oh My Zsh on Mac)?有什么方法可以让 iTerm2 用不同的颜色为每个新标签上色(在 Mac 上使用 Oh My Zsh)?
【发布时间】:2020-03-24 05:33:33
【问题描述】:

我喜欢在 iTerm2 中使用不同颜色的选项卡,以便快速了解每个选项卡所指的内容。当然,我可以在每次打开它们时手动设置它们,或者下载一个允许我从终端本身执行此操作的脚本(参见图片示例——我手动更改了每个选项卡的颜色)。我想知道是否有一种方法(内置于 iTerm2 或通过 Oh My Zsh 脚本)让 iTerm2 在打开选项卡时自动为选项卡使用新的(可能是随机的)颜色?我已经用谷歌搜索了,除了让 SSH 具有不同标签颜色的方法之外找不到任何东西。感谢您的帮助!

【问题讨论】:

    标签: terminal iterm2 oh-my-zsh


    【解决方案1】:

    在不带参数使用color时自动支持随机颜色

    将以下行添加到~/.profile~/.zshrc

    PRELINE="\r\033[A"
    
    function random {
        echo -e "\033]6;1;bg;red;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
        echo -e "\033]6;1;bg;green;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
        echo -e "\033]6;1;bg;blue;brightness;$((1 + $RANDOM % 255))\a"$PRELINE
    }
    
    function color {
        case $1 in
        green)
        echo -e "\033]6;1;bg;red;brightness;57\a"$PRELINE
        echo -e "\033]6;1;bg;green;brightness;197\a"$PRELINE
        echo -e "\033]6;1;bg;blue;brightness;77\a"$PRELINE
        ;;
        red)
        echo -e "\033]6;1;bg;red;brightness;270\a"$PRELINE
        echo -e "\033]6;1;bg;green;brightness;60\a"$PRELINE
        echo -e "\033]6;1;bg;blue;brightness;83\a"$PRELINE
        ;;
        orange)
        echo -e "\033]6;1;bg;red;brightness;227\a"$PRELINE
        echo -e "\033]6;1;bg;green;brightness;143\a"$PRELINE
        echo -e "\033]6;1;bg;blue;brightness;10\a"$PRELINE
        ;;
        *)
        random
        esac
    }
    
    #color    #uncomment to enable automatically set random color when tab created
    

    每次创建新的 iterm2 选项卡后,使用命令 color 自动为其赋予新的/随机颜色。

    如果您希望在创建时自动设置 iterm2-tab 颜色,则只需将 color 添加到 .zshrc / .profile 的末尾或在 function color 之后即可

    【讨论】:

      猜你喜欢
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 2020-05-15
      • 1970-01-01
      相关资源
      最近更新 更多