[ADD] Use my own script to display terminal title

The provided 'vte.sh' script  doesn't quite work on Bash because
$HOSTNAME is empty for some reason.
This commit is contained in:
Bruno BELANYI 2019-11-07 14:49:05 +01:00
parent 4df55b8835
commit 173a0b093c
4 changed files with 49 additions and 20 deletions

View file

@ -6,14 +6,8 @@
[[ $- != *i* ]] && return [[ $- != *i* ]] && return
# Export our directory to Termite for opening new terminals # Export our directory to Termite for opening new terminals
if { [[ "$TERM" == xterm-termite ]] || [[ "$TERM" == xterm ]]; } && if { [[ "$TERM" == xterm-termite ]] || [[ "$TERM" == xterm ]]; }; then
[ -r /etc/profile.d/vte.sh ]; then source ~/.scripts/term-title
if [[ "$TERM" == xterm ]]; then # FIXME: hack to make Xterm work
VTE_VERSION="${VTE_VERSION:-3405}"
fi
. /etc/profile.d/vte.sh
__vte_prompt_command
fi fi
# Make colorcoding available for everyone # Make colorcoding available for everyone

45
scripts/term-title Normal file
View file

@ -0,0 +1,45 @@
# A script to display $USER@$HOST:$PWD with PWD shortened in terminal title
# Taken mostly verbatim from 'vte.sh' provided with VTE-based shells
__term_title_urlencode() (
# This is important to make sure string manipulation is handled
# byte-by-byte.
LC_ALL=C
str="$1"
while [ -n "$str" ]; do
safe="${str%%[!a-zA-Z0-9/:_\.\-\!\'\(\)~]*}"
printf "%s" "$safe"
str="${str#"$safe"}"
if [ -n "$str" ]; then
printf "%%%02X" "'$str"
str="${str#?}"
fi
done
)
__term_title () {
printf "\033]7;file://%s%s\033\\" "${HOST:-}" "$(__term_title_urlencode "${PWD}")"
}
__term_title_prompt_command() {
local pwd='~'
[ "$PWD" != "$HOME" ] && pwd=${PWD/#$HOME\//\~\/}
pwd="${pwd//[[:cntrl:]]}"
if [ -n "$BASH_VERSION" ]; then
if command -v hostname &>/dev/null; then
export HOSTNAME="$(hostname)"
export HOST="$HOSTNAME"
fi
fi
printf "\033]0;%s@%s:%s\033\\%s" "${USER}" "${HOST%%.*}" "${pwd}" "$(__term_title)"
}
case "$TERM" in
xterm*|term_title*)
[ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__term_title_prompt_command;$PROMPT_COMMAND"
[ -n "$ZSH_VERSION" ] && precmd_functions+=(__term_title_prompt_command)
;;
esac
# Launch it once to make sure we display the wanted title
__term_title

View file

@ -45,9 +45,6 @@ if { [ -n "$BASH_VERSION" ] && shopt -q login_shell; } ||
# Use my preferred pager settings for bat # Use my preferred pager settings for bat
export BAT_PAGER="$PAGER $LESS" export BAT_PAGER="$PAGER $LESS"
# Fix terminal title which uses HOSTNAME instead of HOST
export HOSTNAME="$HOST"
fi fi
# Use keychain to handle ssh-agent, in interactive shell too # Use keychain to handle ssh-agent, in interactive shell too

View file

@ -1,13 +1,6 @@
# Export our directory to Termite for opening new terminals # Export our directory to Termite for opening new terminals
if { [[ "$TERM" == xterm-termite ]] || [[ "$TERM" == xterm ]]; } && if { [[ "$TERM" == xterm-termite ]] || [[ "$TERM" == xterm ]]; }; then
[ -r /etc/profile.d/vte.sh ]; then source ~/.scripts/term-title
if [[ "$TERM" == xterm ]]; then # FIXME: hack to make Xterm work
VTE_VERSION="${VTE_VERSION:-3405}"
fi
. /etc/profile.d/vte.sh
__vte_osc7
precmd_functions+=(__vte_prompt_command) # FIXME: why isn't it set above ?
fi fi
# History configuration # History configuration