xfce4 terminal のタイトルを自動的にカレント・ディレクトリにする

ずっと xfce4 teminal などのターミナル・エミュレータのタイトルが”untitled”になっていて切ない思いをしてきました。

ようやく自動的にカレント・ディレクトリをタイトルに出す方法が分かりました。

ぼくの場合、zshを使っているので.zshrcに以下を追加します:

case $TERM in
    xterm*)
        precmd () {print -Pn "\e]0;%~\a"}
        ;;
esac

bashの場合は

case $TERM in
  kterm|xterm|mlterm|cygwin|vt102)
    _termtitle="\h:\w"
    PS1="\[\e]0;${_termtitle}\007\]${PS1}"
    ;;
esac

元ネタは

How to set terminal title dynamically to the current working directory? bashでターミナルのタイトルを動的に変える方法 – (ひ)メモ

です。

Adsense広告