Created
June 26, 2012 08:58
-
-
Save kui/2994553 to your computer and use it in GitHub Desktop.
GNU screen で ssh ログインした時、タイトルにホスト名とかユーザ名を入れるための設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
# -*- coding:utf-8-unix; mode:sh; -*- | |
# | |
# GNU screen で ssh を立ちあげた時に、タイトルを設定するためのスクリプト | |
# | |
# 使い方 | |
# ================== | |
# | |
# .ssh/config の最初の行に下記の三行を追加 | |
# | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# Host * | |
# PermitLocalCommand yes | |
# LocalCommand /path/to/screen_ssh.sh $PPID %n %r | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# | |
# 参考にしたもの | |
# ================== | |
# | |
# * http://www.tenshu.net/p/screenssh.html | |
# * http://ninad.pundaliks.in/blog/2011/10/show-hostname-and-username-during-ssh-in-screen-or-byobus-window-title/ | |
# | |
# 0以外: デバッグ出力する | |
# 0 : 出力しない | |
DEBUG=1 | |
d() { | |
[ $DEBUG != 0 ] && (echo "$@" | tee $HOME/.ssh/screen_ssh.sh) | |
} | |
a() { | |
d "abort: $@" >&2 | |
exit 1 | |
} | |
# 端末上で実行されてる? | |
! tty -s && a "stdin is not a terminal" | |
# [ ! -t 0 ] && a "stdin is not a terminal" | |
# screen 上で実行されてる? | |
[ -z "$STY" ] && a "not in screen" | |
# 引数の数は正しい? | |
[ $# != "3" ] && a "invalid args" | |
# SSH は対話モードで実行されてる?(バッチモードで実行されてない?) | |
grep -a -i "Batchmode yes" /proc/$1/cmdline >/dev/null 2>&1 && a "SSH is in Batch mode" | |
HOST="$2" | |
USER="$3" | |
d "host: $HOST" | |
d "user: $USER" | |
# タイトルの名前どうする? | |
TITLE="$USER@$HOST" | |
d "title: $TITLE" | |
# ウィンドウタイトル変更 | |
echo "\033k$TITLE\033\\" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment