Use wrapper functions for changing title/screen [Closes: Issue779]
authorUlrich Dangel <uli@spamt.net>
Mon, 8 Feb 2010 00:00:03 +0000 (01:00 +0100)
committerUlrich Dangel <uli@spamt.net>
Mon, 8 Feb 2010 21:47:37 +0000 (22:47 +0100)
ZSH prompt escapes in a command while caused strange output. Therefor
do not use print -nP but expand the prompt escapes explicit.  To provide
a convinient method for changing the title Franks screen_printf function
from <http://ft.bewatermyfriend.org/comp/zsh/zshrc.d/zfunct.html> was used
as starting point.

Acked-by: Frank Terbeck <ft@grml.org>
etc/zsh/zshrc

index fe0c8f6..036b4e7 100644 (file)
@@ -1997,6 +1997,26 @@ setopt prompt_subst
 # make sure to use right prompt only when not running a command
 is41 && setopt transient_rprompt
 
+
+function ESC_print () {
+    info_print $'\ek' $'\e\\' "$@"
+}
+function set_title () {
+    info_print  $'\e]0;' $'\a' "$@"
+}
+
+function info_print () {
+    local esc_begin esc_end
+    esc_begin="$1"
+    esc_end="$2"
+    shift 2
+    printf '%s' ${esc_begin}
+    for item in "$@" ; do
+        printf '%s ' "$item"
+    done
+    printf '%s' "${esc_end}"
+}
+
 # TODO: revise all these NO* variables and especially their documentation
 #       in zsh-help() below.
 is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
@@ -2006,9 +2026,9 @@ is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
 
     if [[ $TERM == screen* ]] ; then
         if [[ -n ${VCS_INFO_message_1_} ]] ; then
-            print -nP "\ek${VCS_INFO_message_1_}\e\\"
+            ESC_print ${VCS_INFO_message_1_}
         else
-            print -nP "\ekzsh\e\\"
+            ESC_print "zsh"
         fi
     fi
     # just use DONTSETRPROMPT=1 to be able to overwrite RPROMPT
@@ -2026,7 +2046,7 @@ is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
     [[ ${NOTITLE} -gt 0 ]] && return 0
     case $TERM in
         (xterm*|rxvt*)
-            print -Pn "\e]0;%n@%m: %~\a"
+            set_title ${(%):-"%n@%m: %~"}
             ;;
     esac
 }
@@ -2044,13 +2064,13 @@ preexec () {
     if [[ "$TERM" == screen* ]] ; then
         # local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}       # don't use hostname
         local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
-        echo -ne "\ek$CMD\e\\"
+        ESC_print ${CMD}
     fi
 # adjust title of xterm
     [[ ${NOTITLE} -gt 0 ]] && return 0
     case $TERM in
         (xterm*|rxvt*)
-            print -Pn "\e]0;%n@%m: $1\a"
+            set_title "${(%):-"%n@%m:"}" "$1"
             ;;
     esac
 }