docs:tips_n_tricks:screen.html
This is an old revision of the document!
Table of Contents
screen
show current directory or command in window name when using zsh
Linux
put this in your .zshrc
case "$STY" in "") ;; "$PPID".*) precmd () { let "len = 54 - ${#DISPLAY}" screen -X -S "$PPID" title "$DISPLAY - `pwd|sed -e 's:^.*\(.\{'$len'\}\)$:..\1:g'` ($_my_last_cmd)" } preexec () { screen -X -S "$PPID" title "$DISPLAY - running: $1" _my_last_cmd="$1" # # Maybe $2 or $3 is a better choice - I didn't get the difference yet. You may # # analyse this with the statement: # printf "1:%s\n2:%s\n3:%s\n" "$1" "$2" "$3" >> "/tmp/preexec.$$.log" } ;; esac
Mac OS X
On Mac OS X (maybe on BSD systems in general), screen launches a login
process which then executes the shell. Therefore, the id of the screen session ($STY
) does not start with the parent processes pid ($PPID
), but with the parent pid of the parent process. Therefor, you have to
put this in your .zshrc
case "`ps -o 'command=' -p $PPID`" in "login"*"zsh") pppid="`ps -o 'ppid=' -p $PPID|sed -e 's/^ *//g'`" ;; *) pppid="XXX" ;; esac case "$STY" in "") ;; "$pppid"*) eval " precmd () { let \"len = 54 - \$#DISPLAY\" screen -X -S "$STY" title \"\$DISPLAY - \`pwd|sed -e 's:^.*\(.\{'\$len'\}\)\$:..\1:g'\`\" } preexec () { screen -X -S \"$STY\" title \"\$DISPLAY - running: \$1\" } " ;; esac
show current directory or command in window name when using bash
This is the beginning of an humble try:
case "$STY" in "") ;; "$PPID".*) precmd () { let "len = 54 - ${#DISPLAY}" screen -X -S "$PPID" title "$DISPLAY - `pwd|sed -e 's:^.*\(.\{'$len'\}\)$:..\1:g'`" } preexec () { screen -X -S "$PPID" title "$DISPLAY - running: $1" # # Maybe $2 or $3 is a better choice - I didn't get the difference yet. You may # # analyse this with the statement: # printf "1:%s\n2:%s\n3:%s\n" "$1" "$2" "$3" >> "/tmp/preexec.$$.log" } if [ "$BASH" ] then PROMPT_COMMAND='precmd' screentitle() { preexec "$BASH_COMMAND"; } # # nice try :-/ # trap screentitle DEBUG on_debug() { case "$BASH_COMMAND" in "$PROMPT_COMMAND") ;; *) preexec "$BASH_COMMAND" >> /dev/tty < /dev/null 2>&1 & disown ;; esac } trap on_debug DEBUG fi # as we show user and cwd in screen title, # clear hardstatus in screen: echo -en "\033]0;\007" ;; esac
This seems to break some Pipe chains. There might be a better approach at at twistedmatrix where the idea to use “trap
… DEBUG
” was stolen from
Actually, I consider this trick dirty and hence both solutions.
sample .screenrc file
#remove some stupid / dangerous key bindings bind ^k bind ^\ bind k # # don't lock screen accidently - use if you don't know the accounts password (e.g. when access is managed by ssh keys) # bind x # bind ^x startup_message off vbell on vbell_msg " Klingeling! " bindkey -k kb stuff ^? defscrollback 500 caption always # # show window title and optional # # hardware status line text # caption string "%?%F%{.c.}%?%3n %t%? [%h]%?" # windowlist string "%3n %t %?[%h]%?" # show window title if set, # else hardware status line text windowlist string "%3n %?[%h]%:%t%?" # show clock in caption line caption string "%?%F%{.c.}%?%3n%? [%h]%: %t%?%=| %c:%s " hardstatus on hardstatus alwayslastline msgminwait 0
docs/tips_n_tricks/screen.html.1310573792.txt.gz · Last modified: 13.07.2011 18:16 CEST by peter