dot/shell-rc: Factor out the terminal and screen title-setting.
[profile] / dot / shell-rc
index 67ad457..d6a218a 100644 (file)
@@ -62,11 +62,12 @@ __mdw_runhook () {
 ### Prompt machinery.
 
 __mdw_host=$(hostname)
+__mdw_hqual=
+__mdw_hqual=$__mdw_hqual${SCHROOT_CHROOT_NAME+/$SCHROOT_CHROOT_NAME}
+__mdw_hqual=$__mdw_hqual${CROSS_BUILDENV+/$CROSS_BUILDENV}
 __mdw_set_prompt_hacks () { host=$__mdw_host; dir=""; }
 
 __mdw_set_prompt_pieces () {
-  local hqual
-  hqual=""
 
   ## Fancy highlighting in some terminals.
   local bold unbold nl gitcolour rccolour uncolour
@@ -108,11 +109,9 @@ __mdw_set_prompt_pieces () {
 
   ## If this is an schroot environment or some other interesting augmented
   ## environment then point this out.
-  hqual="$hqual${SCHROOT_CHROOT_NAME+/$SCHROOT_CHROOT_NAME}"
-  hqual="$hqual${CROSS_BUILDENV+/$CROSS_BUILDENV}"
 
   ## Put together the main pieces.
-  __mdw_prompt_left="$nl$bold$left$sec_l$u$host$hqual$sec_r$dir"
+  __mdw_prompt_left="$nl$bold$left$sec_l$u$host$__mdw_hqual$sec_r$dir"
   __mdw_prompt_git_left="$unbold$gitcolour"
   __mdw_prompt_git_right="$uncolour$bold"
   __mdw_prompt_rc_left="$unbold$rccolour"
@@ -146,12 +145,30 @@ __mdw_set_prompt () {
   esac
 }
 
-__mdw_screen_precmd () { printf "\ek%s\e\\" "$__mdw_shell"; }
-__mdw_screen_preexec () { printf "\ek%s\e\\" "$1"; }
+__mdw_xterm_settitle () {
+  printf >/dev/tty \
+    "\e]2;%s@%s:%s – %s\e\\" \
+    "$USER" "$__mdw_host" "$PWD" \
+    "$1"
+}
+__mdw_xterm_precmd () { __mdw_xterm_settitle "$__mdw_shell"; }
+__mdw_xterm_preexec () { __mdw_xterm_settitle "$1"; }
+
+__mdw_screen_settitle () {
+  printf >/dev/tty \
+    "\ek%s\e\\" \
+    "$1"
+}
+__mdw_screen_precmd () { __mdw_screen_settitle "$__mdw_shell"; }
+__mdw_screen_preexec () { __mdw_screen_settitle "$1"; }
 
 if [ -t 0 ]; then
-  case ${STY+t},${__mdw_precmd_hook+t},${__mdw_preexec_hook+t} in
-    t,t,t)
+  case ${STY+t},${__mdw_precmd_hook+t},${__mdw_preexec_hook+t},${TERM} in
+    ,t,t,xterm*)
+      __mdw_addhook __mdw_precmd_hook __mdw_xterm_precmd
+      __mdw_addhook __mdw_preexec_hook __mdw_xterm_preexec
+      ;;
+    t,t,t,*)
       __mdw_addhook __mdw_precmd_hook __mdw_screen_precmd
       __mdw_addhook __mdw_preexec_hook __mdw_screen_preexec
       ;;
@@ -180,6 +197,7 @@ alias e="$EDITOR"
 alias svn="svnwrap svn"
 alias @="ssh"
 alias make="nice make"
+alias cross-run="nice cross-run"
 alias gdb="gdb -q"
 
 ###--------------------------------------------------------------------------