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.
pull/949/head
Álvaro Brey 2017-04-26 17:11:53 +02:00
parent 1155e536da
commit 597285cdfd
No known key found for this signature in database
GPG Key ID: CFE28F23E51968FA
2 changed files with 17 additions and 3 deletions

View File

@ -1,18 +1,28 @@
cite about-plugin cite about-plugin
about-plugin 'automatically set your xterm title with host and location info' 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 () { set_xterm_title () {
local title="$1" local title="$1"
echo -ne "\033]0;$title\007" echo -ne "\033]0;$title\007"
} }
precmd () { 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 () { 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 case "$TERM" in

View File

@ -36,6 +36,10 @@ export SCM_CHECK=true
# Will otherwise fall back on $USER. # Will otherwise fall back on $USER.
#export SHORT_USER=${USER:0:8} #export SHORT_USER=${USER:0:8}
# Set Xterm/screen/Tmux title with shortened command and directory.
# Uncomment this to set.
#export SHORT_TERM_LINE=true
# Set vcprompt executable path for scm advance info in prompt (demula theme) # Set vcprompt executable path for scm advance info in prompt (demula theme)
# https://github.com/djl/vcprompt # https://github.com/djl/vcprompt
#export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt #export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt