LoginSignup
11

More than 5 years have passed since last update.

ターミナルのウィンドウとタブに自動的に名前をつける

Posted at

ターミナルのウィンドウとタブの名前は全部 zsh とかになっていて、あまり意味がない。ウィンドウにはカレントディレクトリのフルパスを、タブにはディレクトリ名を表示するように設定する。

~/.zshrc

function precmd() {
  # カレントディレクトリを $HOME を ~ として表示
  local wname=`pwd | sed -e "s|$HOME|~|"`
  # カレントディレクトリ名
  local tname=`pwd | sed -e 's|^.*/||'`

  echo -ne "\033]2;$wname\007" # window title
  echo -ne "\033]1;$tname\007" # tab title
}

iTerm2.app だけかもしれないけど、\033]1; でタブの名前、\033]2; でウィンドウの名前が別々につけられる。

iterm_titles.png

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11