Support shortened command & dir name in xterm title plugin

This allows the user to see only last level of the current path (if dirname is longer than 8 chars),
and only first word of the ongoing command line if it's longer than 8 chars.
This commit is contained in:
Álvaro Brey
2017-04-26 17:11:53 +02:00
parent 1155e536da
commit 597285cdfd
2 changed files with 17 additions and 3 deletions

View File

@@ -1,18 +1,28 @@
cite about-plugin
about-plugin 'automatically set your xterm title with host and location info'
short_dirname () {
local dir_name=`dirs -0`
[ "$SHORT_TERM_LINE" = true ] && [ ${#dir_name} -gt 8 ] && echo ${dir_name##*/} || echo $dir_name
}
short_command () {
local input_command="$@"
[ "$SHORT_TERM_LINE" = true ] && [ ${#input_command} -gt 8 ] && echo ${input_command%% *} || echo $input_command
}
set_xterm_title () {
local title="$1"
echo -ne "\033]0;$title\007"
}
precmd () {
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} `dirs -0` $PROMPTCHAR"
set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} `short_dirname` $PROMPTCHAR"
}
preexec () {
set_xterm_title "$1 {`dirs -0`} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
set_xterm_title "$(short_command $1) {`short_dirname`} (${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}})"
}
case "$TERM" in