Browse Source

[environment] add customizable term title

Adds customizable terminal/window title. Set `${ztermtitle}` in `.zimrc`
to use this functionality.

Check the notes added in templates/zimrc for additional usage info.

Closes #52
Matt Hamilton 7 years ago
parent
commit
cc34e3f310
3 changed files with 24 additions and 0 deletions
  1. 2 0
      modules/environment/README.md
  2. 11 0
      modules/environment/init.zsh
  3. 11 0
      templates/zimrc

+ 2 - 0
modules/environment/README.md

@@ -5,6 +5,8 @@ Sets generic Zsh built-in environment options.
 
 Also enables smart URL-pasting. This prevents the user from having to manually escape URLs.
 
+Uses `.zimrc` defined `${ztermtitle}` variable to set the terminal title, if defined.
+
 ZSH Options
 -----------
 

+ 11 - 0
modules/environment/init.zsh

@@ -46,3 +46,14 @@ if [[ -z ${PAGER} ]]; then
     export PAGER=more
   fi
 fi
+
+# sets the window title and updates upon directory change
+# more work probably needs to be done here to support multiplexers
+if (($+ztermtitle)); then
+  case ${TERM} in
+    xterm*)
+      precmd() { print -Pn "\e]0;${ztermtitle}\a" }
+      precmd  # we execute it once to initialize the window title
+      ;;
+  esac
+fi

+ 11 - 0
templates/zimrc

@@ -43,6 +43,17 @@ zprompt_theme='steeef'
 #setopt CORRECT
 
 #
+# Environment
+#
+
+# Set the string below to the desired terminal title format string.
+# The terminal title is redrawn upon directory change, however, variables like 
+# ${PWD} are only evaluated once. Use prompt expansion strings for dynamic data:
+#   http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html#Simple-Prompt-Escapes
+# The example below uses the following format: 'username@host:/current/directory'
+ztermtitle='%n@%m:%~'
+
+#
 # Input
 #