Skip to content

Commit

Permalink
Zsh: Update the terminal title routines.
Browse files Browse the repository at this point in the history
  • Loading branch information
StanAngeloff committed Jun 7, 2012
1 parent 3fda2e1 commit 2cb2d55
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions .zshrc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -175,31 +175,33 @@ bindkey ' ' magic-space
bindkey "^[m" copy-prev-shell-word bindkey "^[m" copy-prev-shell-word


# Fancy terminal title # Fancy terminal title
function title { function _terminal_title {
if [[ "$TERM" == screen* ]] || [[ "$ALTTERM" == screen* ]]; then if [[ "$TERM" == screen* ]] || [[ "$ALTTERM" == screen* ]]; then
print -nR $'\ek'$*$'\e\\' print -Pn "\ek$1:q\e\\" # Set `screen` hardstatus.
elif [[ "$TERM" == xterm* ]] || [[ "$TERM" == rxvt* ]]; then elif [[ "$TERM" == xterm* ]] || [[ "$TERM" == rxvt* ]]; then
print -nR $'\033]0;'$*$'\a' print -Pn "\e]2;$2:q\a" # Set window name.
print -Pn "\e]1;$1:q\a" # Set icon (=tab) name (will override window name on broken terminal).
fi fi
} }


function chpwd { function _before_directory_change {
echo "$( pwd -P )" > "$ZSH/.last_directory" _terminal_title "%15<..<%~%<<" "%n@%m: %~"
}

function precmd {
title zsh "$PWD"
if declare -f _z > /dev/null; then if declare -f _z > /dev/null; then
_z --add "$( pwd -P )" _z --add "$( pwd -P )"
fi fi
} }


function preexec { function _before_command_execute {
emulate -L zsh emulate -L zsh
local -a cmd; cmd=(${(z)1}) setopt extended_glob
title $cmd[1]:t "$cmd[2,-1]" local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} # Command name only, or if this is `sudo` or `ssh`, the next command.
_terminal_title "$CMD" "%100>...>$2%<<"
} }


autoload -U add-zsh-hook
add-zsh-hook precmd _before_directory_change
add-zsh-hook preexec _before_command_execute

# set PATH so it includes user's private bin if it exists. # set PATH so it includes user's private bin if it exists.
[ -d "$HOME/bin" ] && PATH="$HOME/bin:$PATH" [ -d "$HOME/bin" ] && PATH="$HOME/bin:$PATH"


Expand Down

0 comments on commit 2cb2d55

Please sign in to comment.