screen

http://d.hatena.ne.jp/xaxe/20061002

オプション

  • -r デタッチしたセッションに再接続
  • -ls セッション一覧

キーバインド

  • (prefix) d デタッチ
  • (prefix) : コマンド入力
  • (prefix) [ コピーモード
    • 移動はviライク
    • スペースキーでマーク
    • 履歴バッファがあり、スクロールバックできる
  • (prefix) A タイトル

ウィンドウのタイトル

(.screenrc)
hardstatus alwayslastline "%`%-w%{=b bw}%n %t%{-}%+w"

タイトルを変更するには、通常の仮想端末のタイトルを変更するのと同じように、
シェルからタイトル文字列エスケープシーケンスを送る。
参照: man screen のTITLES

(.zshrc)
# screen title-string escape-sequence
if [ $TERM = 'screen' ]; then
        # precmd is called just before the prompt is printed
        precmd() {
                echo -n '^[kzsh^[\'
        }
        # preexec is called just before any command line is executed
        preexec() {
                print -Pn "^[k%20>...>${(V)2//\%/\%\%}"; echo -n '^[\'
        }
fi
  • エスケープシーケンスは ^[kタイトル^[\
  • preexecの$2(実行されようとしているコマンドライン)をVフラグ(catの-vオプションと同じ)で展開
  • $2をプロンプト展開でトランケートするので、%を%%に置換
  • 最後の ^[\ はトランケートされないように、切り離して出力

概念図

コマンド <===> シェル <===> screen <===> ターミナル(PuTTY)