美文网首页
iTerm:自定义窗口标题

iTerm:自定义窗口标题

作者: LightingContour | 来源:发表于2019-07-21 15:56 被阅读0次
    窗口标题预览

    按照如下配置即可配置成上图所示样式。

    实现方案

    更改配置文件

    如果是使用zsh,编辑~/.zshrc,关闭auto_title、增加precmd()。

    # Uncomment the following line to disable auto-setting terminal title.
    DISABLE_AUTO_TITLE="true"
    # 设置标题栏
    function precmd () {
      print -Pn - '\e]0;%1~\a'
    }
    

    如果是使用bash,编辑~/.bash_profile,同理。

    更改iTerm设置

    iTerm2-Preferences-Profiles-Terminal,将Terminal may set tab/window title勾选.


    配置iTerm

    如果配置文件是开着iTerm改的,关闭iTerm重启下就好了。

    扩展

    如果想要显示整个目录
    \e]0;%1~\a改为\e]1;$PWD\a即可

    如果想要显示两个文件夹层级
    \e]0;%1~\a改为\e]0;%2~\a即可,可类推3456

    参考文章

    https://superuser.com/questions/292652/change-iterm2-window-and-tab-titles-in-zsh
    https://www.lijiaocn.com/%E6%8A%80%E5%B7%A7/2017/12/14/change-bash-title.html
    https://apple.stackexchange.com/questions/90725/for-iterm2-how-do-i-make-the-working-directory-appear-in-the-window-title

    相关文章

      网友评论

          本文标题:iTerm:自定义窗口标题

          本文链接:https://www.haomeiwen.com/subject/flzmlctx.html