user@host
ウィンドウタイトルでどのコンピュータに接続されているかを簡単に知るために、ターミナルタイトルをに設定したいと思います。 SSHまたはGNOME端末でこれを行う方法はありますか?
ベストアンサー1
はい。以下は、配布に依存しない PS1 を使用する bash の例です。
特にエスケープシーケンスが\[\e]0; __SOME_STUFF_HERE__ \a\]
重要です。より明確にするために、これを別の変数として編集しました。
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
TITLEBAR='\[\e]0;\u@\h\a\]'
# Same thing.. but with octal ASCII escape chars
#TITLEBAR='\[\033]2;\u@\h\007\]'
if [ "$color_prompt" = yes ]; then
PS1="${TITLEBAR}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ "
else
PS1="${TITLEBAR}\u@\h:\W\$ "
fi
unset color_prompt force_color_prompt
また、使用しているターミナルプログラムとシェルに応じてxtermヘッダーを設定する方法はいくつかあります。たとえば、KDEのKonsoleを使用している場合は、Settings
-> Configure Profiles
-> Edit Profile
->Tabs
設定Tab title format
とRemote tab title format
設定に移動してタイトル設定を上書きできます。
また、次の点も確認してみてください。
- これ「xterm タイトルの変更方法」 FAQ他の殻の場合
- これ「即時魔法」のヒントBashで動作するエスケープシーケンスの良い参考資料です。
- これBashプロンプトHOWTOANSIカラーエスケープシーケンスへの参照。