Added title plugin.
This commit is contained in:
parent
67a843977e
commit
731394c0c1
60
plugins/title/title.plugin.zsh
Executable file
60
plugins/title/title.plugin.zsh
Executable file
@ -0,0 +1,60 @@
|
|||||||
|
#!/bin/zsh
|
||||||
|
|
||||||
|
setopt extended_glob
|
||||||
|
|
||||||
|
function print_title() {
|
||||||
|
if [ -n "$SSH_CONNECTION" ]; then
|
||||||
|
print -Pn "(%n@%m) "
|
||||||
|
fi
|
||||||
|
|
||||||
|
print -Pn "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define a title function per terminal
|
||||||
|
case "$TERM" in
|
||||||
|
# GNU Screen:
|
||||||
|
( screen | screen.* | screen-* )
|
||||||
|
function title {
|
||||||
|
print -Pn "\ek"
|
||||||
|
print_title $*
|
||||||
|
print -Pn "\e\\"
|
||||||
|
print -Pn "\e]2;"
|
||||||
|
print_title $*
|
||||||
|
print -Pn "\a"
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
|
||||||
|
# X terminals
|
||||||
|
( *xterm* | *rxvt )
|
||||||
|
function title {
|
||||||
|
print -Pn "\e]2;"
|
||||||
|
print_title $*
|
||||||
|
print -Pn "\a"
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
function title {
|
||||||
|
# Unknown terminal, do nothing.
|
||||||
|
}
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Override precmd function to display status code if non-zero and update title
|
||||||
|
# with path, and hostname if remote
|
||||||
|
function precmd {
|
||||||
|
# Get return code and display it if non-zero
|
||||||
|
retcode=$?
|
||||||
|
if [ $retcode -ne 0 ]; then
|
||||||
|
# TODO check termcap to see if we can use color
|
||||||
|
print -P "\e[01;31m -- Non zero exit: $retcode --\e[0m"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Show the current directory in title.
|
||||||
|
title "%~"
|
||||||
|
}
|
||||||
|
|
||||||
|
function preexec () {
|
||||||
|
emulate -L zsh
|
||||||
|
local -a cmd; cmd=(${(z)1})
|
||||||
|
title $cmd[1]:t "$cmd[2,-1]"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user