From a52e8a9469de210278509611b72c9fbbde28b445 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Tue, 22 Sep 2015 13:25:25 +0300 Subject: [PATCH] Deduplicate code by creating a set_title function --- pure.zsh | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/pure.zsh b/pure.zsh index b104ac4..b7acaee 100644 --- a/pure.zsh +++ b/pure.zsh @@ -84,17 +84,26 @@ prompt_pure_check_git_arrows() { [[ -n $arrows ]] && prompt_pure_git_arrows=" ${arrows}" } +prompt_pure_set_title() { + # tell the terminal we are setting the title + print -n '\e]0;' + # show hostname if connected through ssh + [[ -n $SSH_CONNECTION ]] && print -Pn '(%m) ' + case $1 in + expand-prompt) + print -Pn $2;; + ignore-escape) + print -rn $2;; + esac + # end set title + print -n '\a' +} + prompt_pure_preexec() { prompt_pure_cmd_timestamp=$EPOCHSECONDS - # tell the terminal we are setting the title - print -Pn "\e]0;" - # show hostname if connected through ssh - [[ "$SSH_CONNECTION" != '' ]] && print -Pn "(%m) " - # shows the current dir and executed command in the title when a process is active - # (use print -r to disable potential evaluation of escape characters in cmd) - print -nr "$PWD:t: $2" - print -Pn "\a" + # shows the current dir and executed command in the title while a process is active + prompt_pure_set_title 'ignore-escape' "$PWD:t: $2" } # string length ignoring ansi escapes @@ -190,12 +199,8 @@ prompt_pure_precmd() { # check for git arrows prompt_pure_check_git_arrows - # tell the terminal we are setting the title - print -Pn "\e]0;" - # show hostname if connected through ssh - [[ "$SSH_CONNECTION" != '' ]] && print -Pn "(%m) " # shows the full path in the title - print -Pn "%~\a" + prompt_pure_set_title 'expand-prompt' '%~' # get vcs info vcs_info