Skip to content

Commit

Permalink
Set title via atomic print statement (#399)
Browse files Browse the repository at this point in the history
Previously, `setopt xtrace` would produce terminal bell rings (by \a)
whenever the title was set because of debug output between print
statements. As a result, the title was not set and the terminal bell
rang.

This change also utilizes the improved ssh connection detection to
provide hostname in title when changing user on remote machines.
  • Loading branch information
mafredri authored May 2, 2018
1 parent 5a39be4 commit 49ca46d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,22 @@ prompt_pure_set_title() {
/dev/ttyS[0-9]*) return;;
esac

# tell the terminal we are setting the title
print -n '\e]0;'
# show hostname if connected through ssh
[[ -n $SSH_CONNECTION ]] && print -Pn '(%m) '
# Show hostname if connected via ssh.
local hostname=
if [[ -n $prompt_pure_state[username] ]]; then
# Expand in-place in case ignore-escape is used.
hostname="${(%):-(%m) }"
fi

local -a opts
case $1 in
expand-prompt)
print -Pn $2;;
ignore-escape)
print -rn $2;;
expand-prompt) opts=(-P);;
ignore-escape) opts=(-r);;
esac
# end set title
print -n '\a'

# Set title atomically in one print statement so that it works
# when XTRACE is enabled.
print -n $opts $'\e]0;'${hostname}${2}$'\a'
}

prompt_pure_preexec() {
Expand Down

0 comments on commit 49ca46d

Please sign in to comment.