From 597285cdfd39e86395de63abc81fec4cf787939d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Wed, 26 Apr 2017 17:11:53 +0200 Subject: [PATCH] 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. --- plugins/available/xterm.plugin.bash | 16 +++++++++++++--- template/bash_profile.template.bash | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index c16c5b8f..e4934a66 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -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 diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 10eaaede..4abc30de 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -36,6 +36,10 @@ export SCM_CHECK=true # Will otherwise fall back on $USER. #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) # https://github.com/djl/vcprompt #export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt