Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

title functions

  • Loading branch information...
commit 4b82836fad64a31b1b22f774599dc2a7dbe4caff 1 parent bfa861c
@Oshuma authored
Showing with 28 additions and 0 deletions.
  1. +28 −0 lib/functions.zsh
View
28 lib/functions.zsh
@@ -34,3 +34,31 @@ function cleanup_mongodb() {
echo "Done."
}
+
+# Format titles for screen and rxvt.
+function title() {
+ # escape '%' chars in $1, make nonprintables visible
+ a=${(V)1//\%/\%\%\%}
+
+ # truncate command and join lines
+ a=$(print -Pn "%40>...>$a" | tr -d "\n")
+
+ case $TERM in
+ screen)
+ print -Pn "\ek$a:$3\e\\" # screen title (in ^A")
+ ;;
+ xterm*|rxvt)
+ print -Pn "\e]2;$2 | $a:$3\a" # plain xterm title
+ ;;
+ esac
+}
+
+# precmd is called before the prompt is printed
+function precmd() {
+ title "zsh" "$USER@%m" "%55<...<%~"
+}
+
+# preexec is called just before any command line is executed
+function preexec() {
+ title "$1" "$USER@%m" "%35<...<%~"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.