Merge pull request #164 from sindresorhus/set-title-function

Deduplicate code by creating a set_title function
This commit is contained in:
Sindre Sorhus
2015-10-02 17:06:02 +07:00

View File

@@ -84,17 +84,26 @@ prompt_pure_check_git_arrows() {
[[ -n $arrows ]] && prompt_pure_git_arrows=" ${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_preexec() {
prompt_pure_cmd_timestamp=$EPOCHSECONDS prompt_pure_cmd_timestamp=$EPOCHSECONDS
# tell the terminal we are setting the title # shows the current dir and executed command in the title while a process is active
print -Pn "\e]0;" prompt_pure_set_title 'ignore-escape' "$PWD:t: $2"
# 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"
} }
# string length ignoring ansi escapes # string length ignoring ansi escapes
@@ -190,12 +199,8 @@ prompt_pure_precmd() {
# check for git arrows # check for git arrows
prompt_pure_check_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 # shows the full path in the title
print -Pn "%~\a" prompt_pure_set_title 'expand-prompt' '%~'
# get vcs info # get vcs info
vcs_info vcs_info