Xterm-Title mini-HOWTO <author>Winfried Trper,<tt/winni@xpilot.org/ <date>Version 1.3 22 Oct 1996 <trans>Tetsu Isaji, <tt/isaji@mxu.meshnet.or.jp/ <tdate>18 Dec 1997 <abstract> このmini-HOWTOはxtermのタイトルバー表示をエスケープシーケンス で制御するためのドキュメントです。 [<em/訳注:/&dquot;<ref id="other-info" name="関連情報">&dquot;章には それ以外にウィンドウマネージャやターミナルエミュレータの装飾についての情報を 追加しました。] </abstract> <!-- contents --> <toc> <sect>はじめに <p> <!-- "Isn't this boring?" most people will ask. I just do a [snip] to place arbitary strings into the titlebar of the xterm. Ok, that's right but you may want to change it after startup ... --> 「この文書っておもしろいの?」と思う人が多いかもしれません。<tt/xterm/の タイトルバーに適当な文字列を入れたいなら <tscreen><verb> xterm -T "Rent this place for your advertisement" \ -n "The name of the icon could be yours, too" & </verb></tscreen> とすれば良いだけです。 OK、そのとおりです。でも起動時以外に文字列を変えた いこともあるかもしれないでしょう... <sect>エスケープシーケンス <p> <!-- To change the title while the xterm is running, you just send a special sequence of characters to it. Such a special sequence is named "escape sequence" and usally not displayed on the screen but causing certain actions. --> <tt/xterm/が起動している時にタイトルを変更するには、特殊キャラクターを <tt/xterm/に送ればよいのです。そのような特殊キャラクターは「エスケープシ ーケンス」と名付けられています。これらは画面上に表示されませんがなんらか のアクションを生じさせます。 <p> <!-- For example, if you press <ctrl-v> <Esc> <c> <Enter>, your xterm should reset (e.g. clear the screen). The <ctrl-v> and <enter> are only needed to make the bash printing the actual sequence <esc> <c>. --> 例えば、<ctrl-v> <Esc> <c> <Enter>と押せば画面は リセットされます(画面の消去)。<ctrl-v>と<enter>は実際のシーケ ンス<esc> <c>を画面上に表示させるために必要です。 <!-- Note that I refer to keystrokes by enclosing the label of that key by <>. --> ここでキーストロークは<>で区切っていることに注意して下さい。<> は入力する必要はありません。 <sect>タイトルの表示 <p> <!-- Now, to change the titlebar and icon of the xterm you just use the escape-sequences --> <tt/xterm/のタイトルバーとアイコンを変更するにはつぎのエスケープシーケンス を使います <tscreen><verb> <esc> <]> <2> <;> 新しいタイトルをセット <esc> <]> <1> <;> 新しいアイコン名をセット(注:アイコン化された時の名前) </verb></tscreen> <!-- To send those sequences to the xterm, we no longer type them on the command-line, but we use the program `echo': --> <tt/xterm/にこれらのシーケンスを送るために、プログラム&dquot;echo&dquot; を使えば、もうコマンドラインで入力する必要はなくなります。 <tscreen> <verb> echo -e "\033]2; You can rent this place for a commercial. \007" </verb> </tscreen> <!-- As you might have guessed `\033' is the octal representation of the escape-character and '-e' enables this syntax. You must terminate the string that should show up in the title with a <ctrl-g> aka "the lovely beep". --> ここでお気づきになったと思いますが、`\033'はエスケープシーケンス の8進数表示で、'-e'でこの表現を指定できるようにしています。 タイトルに表示したい文字列の最後は<ctrl-g>で終わらせる必要があり ます(<ctrl-g>は「ラブりーな」 beep 音を発生させるキーです)。 <sect>プロンプトの表示 <p> <!-- One useful application for those features is to move the information usally found in the command-prompt into the xterm-title: lets assume you have defined you command-prompt as --> この特徴を生かした便利な使い方をひとつ。通常のコマンドプロンプトに表示され る情報を、<tt/xterm/のタイトルに移動させる方法があります。以下のように変数 を定義すると <tscreen><verb> export PS1='\u@\h:\w> ' </verb></tscreen> この結果、次のように表示されます。 <tscreen><verb> winni@FeilSurf:~/mail> </verb></tscreen> <!-- What happens, if you change to the directory "/afs/rrz.uni-koeln.de /pub/packages/linux/kernel/v2.0"? Right, the prompt gets longer and leaves less space for typing commands: --> もしディレクトリを&dquot;<tt>/afs/rrz.uni-koeln.de/pub/packages/linux /kernel/v2.0</tt>&dquot;に変更したらどうなるでしょうか?プロンプトは長くなり コマンドの入力をする場所が狭くなってしまいます。 <tscreen> <verb> winni@FeilSurf:/afs/rrz.uni-koeln.de/pub/packages/linux/kernel/v2.0> </verb> </tscreen> <!-- This is odd. But - if you put this information into the title-bar, everything is fine: --> これは繁雑です。しかしタイトルバーにこの情報を置いてしまえば全て解決し ます。 <tscreen><verb> export PS1='\033]2; \u@\h:\w \007bash> ' </verb></tscreen> <!-- The command above echoes the needed escape-sequences and leaves as prompt: --> 上記コマンドで必要なエスケープシーケンスをエコーし、プロンプト <tscreen><verb> bash> _ </verb></tscreen> のみ表示させます。 <!-- Unfortunatly the maximum length of the value of PS1 is limited to somewhat around 60 (?) chars and so it's not suited in all cases. Another idea is to re-define shell-builtins like "cd" to echo the escape-sequences but this has the ugly side-effect of a nervous title-bar when running shell-scripts ... (yes, every "cd" changes the title). --> 残念なことに<tt/PS1/の最大の長さは60文字程度という制限があるので 全ての場合でこれがうまくいくわけではありません。他のアイディアは &dquot;cd&dquot;といったシェル内蔵のものを<tt/echo/エスケープシーケンス に再定義するこですが、これだとシェルスクリプトを実行した時タイトルバーの その他の影響が生じてしまいやっかいです(どの&dquot;cd&dquot;でもタイトル を変更してしまいます)。 <!-- The most reliable approach seems to me the usage of the environment-variable "PROMPT_COMMAND". The content of this variable is executed after a program has finished and before the bash prompts at you again. The following is very useful in a networked environment with many xterms opened: --> もっとも確かなアプローチは環境変数&dquot;<tt/PROMPT_COMMAND/&dquot;を使うこと のようです。この変数の中身はプログラムが終了した後と<tt/bash/プロンプト が再び表示される前に実行されるというものです。以下のようにすれば ネットワーク環境で<tt/xterm/をたくさん開く時など便利です。 <verb> export PROMPT_COMMAND='echo -ne "\033]2;$LOGNAME@$HOST Directory: \ $PWD\007\033]1;$LOGNAME@$HOST\007" </verb> 特にウィンドウマネージャーのウィンドウリストを見る時など便利でしょう。 <!-- ... especially when you look at the "window list" of your window-manager. And to make it perfect, we only set this variable when we are in an xterm: --> さらにこれらを以下のようなスクリプトに書いておけば完璧です。xtermを使って いる時にこの環境変数をセットするだけです。 <code> if [ "$TERM" = "xterm" -o "$TERM" = "xterm-color" -o \ "$TERM" = "rxvt" -o "$TERM" = "vs100" ] then PS1='bash> ' PS2='bash>> ' PS3='bash>>> ' export PROMPT_COMMAND='echo -ne "\033]2;$LOGNAME@$HOST \ Directory: $PWD\007\033]1;$LOGNAME@$HOST\007"' fi </code> <!-- printenv TERM --> <!-- Note that the prompt "bash> " makes the command-line somewhat more consistent because many programs put their name in the front (gnuplot, ncftp, gap, kash, ...). But even this has the drawback of messing up some programs that spawn up sub-shells like "ytalk". If you get bitten by it, issue --> プロンプト&dquot;bash>&dquot;は、多くのプログラム(gnuplot,ncftp, gap, kash, ...)がプログラム名をはじめに置いているので、同じように統一しました。 しかしこれでも&dquot;ytalk&dquot;のようなサブシェルを起動するプログラム では乱れてしまうという障害があります。もしこれに出くわしたら <tscreen><verb> unset PROMPT_COMMAND </verb></tscreen> として下さい。 <p> Happy Linuxing<p> -Winfried Trumper <htmlurl url="winni@xpilot.org" name="winni@xpilot.org"> <sect>その他 <sect1>CREDITS: <p> Ville Voutilainen <vvoutila@raita.oulu.fi> <p> Noticed the ;s are missing from the escape-sequences in the "first half" of the document(ドキュメント前半部でエスケープシーケンスから セミコロンが落ちていたので注意して下さい)。 <sect1>補追1: <p> <!-- Don't ever use raw "escape-sequences" in any of your programs! Let the program "tput" choose the right sequences from the environment-variable '$TERM' plus your symbolic description of the action to perform. See tput(1) for details (enter "man 1 tput" at the command prompt). The escape-sequences for the xterm-titlebar are the only exception from the above rule. --> どのようなプログラムを作るときでもエスケープシーケンスを直接使わないように して下さい。プログラム&dquot;tput&dquot;を使って、環境変数<tt/$TERM/ と実行させたいアクションに対応したシンボリックな記法(<em/訳注:/該当するアク ションに関する変数))から適切なシーケンスを選ぶようにして下さい。詳細はtput(1) を参照して下さい(コマンドプロンプトで&dquot;<tt/man 1 tput/&dquot;として参照 できます)。(<em/訳注/<tt/tput/:ターミナルの初期化や<tt/terminfo/データベース の問い(query)) <sect1>補追2: <p> <!-- If you want to know the "escape-sequences" an xterms understand, then have a look at the sources for rxvt, it contains the file "xterm.seq" in the "doc/"-directory. --> 「エスケープシーケンス」について知りたい時は&dquot;rxvt&dquot;のソースを参照 してみて下さい。エスケープシーケンスについて&dquot;xterm.seq&dquot;というファ イルが&dquot;doc/&dquot;ディレクトリにあります。 <p>以上ここまでが原文。 <hrule> <sect>関連情報<label id="other-info"> <p> <itemize> <item>&dquot;<it/Linux Japan/&dquot;<tt/Vol.3 p.198/ xtermタイトルバーについての記事。 <item>ラスターマン氏のホームページ<p> <it/Rastemann HOMEPAGE/ : <tt/highlightment, xdm, rxvt-xpm/などウィンドウ マネージャやターミナルエミュレータの見栄えをよくするプログラム、設定などに ついての情報があります。以下、 <url url="http://www.cse.unsw.edu.au/˜s2154962/linux.html"> <itemize> <item>ターミナルエミュレータrxvtの背景にイメージファイルを貼り付ける。 <verb> rxvt-xpm: ソース:rxvt-2.19.3.XPM.tar.gz src/Makefileに"-DKANJI"オプションを書き込んでコンパイルすれば 日本語の表示もできるようになります(kxvtあるいはpxvtとリネーム します)。kinput2 protocolを実装していないので、kinput2による 入力はできません。また日本語表示も不完全なようです。 実行例:rxvt -pixmap /home/user/rosamexl.xpm & </verb> <item>XDMの見栄えをよくする。 <verb> ソース:xdm_setup_files.tar.gz 実行例:上記ページを参照 関連:"Linux" Japan Vol.3 p.120 XBanner + xdm </verb> <item>ハイライトメント:<p> ヴィンドウマネージャの見栄えを良くします(フレーム枠なども)。 FVWM-XPM、ppmtile(背景に貼り付けるイメージの処理)。 <item>その他:<p> <tt/ppm2ansi.tar.gz 、xflame.tar.gz、xripple.tar.gz/など。 </itemize> </itemize> [ 訳者 : 伊佐治 哲 <tt/isaji@mxu.meshnet.or.jp/ <p> 校正 : 中野さん NAKANO Takeo <tt/nakano@apm.seikei.ac.jp/ ] </article>