From 98c976134487b8901eef02ea132f2217d0552550 Mon Sep 17 00:00:00 2001 From: James Bunton Date: Tue, 12 Mar 2019 22:50:37 +1100 Subject: [PATCH] bash: include hostname in all xterm titles - Reorderd hostname in print_title_prompt to match vim/emacs - Added hostname to print_title_exec - Cleanup: Use local instead of unset in print_exit_code - Cleanup: Use \e and \a instead of \033 and \007 --- .bashrc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.bashrc b/.bashrc index 36339bc..06b9d25 100644 --- a/.bashrc +++ b/.bashrc @@ -1,5 +1,5 @@ # shellcheck disable=SC1090 disable=SC1091 # -- Can't follow non-constant source -# shellcheck disable=SC1003 # -- Don't complain about '\033\\' +# shellcheck disable=SC1003 # -- Don't complain about '\e\\' ########################### # Settings for all shells # @@ -130,8 +130,8 @@ function my_svn_ps1 { # Two line prompt PS1='' -PS1="$PS1"'\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]' -PS1="$PS1"'\[\033[01;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\033[00m\]' +PS1="$PS1"'\[\e[01;31m\]\u@\h\[\e[00m\]:\[\e[01;34m\]\w\[\e[00m\]' +PS1="$PS1"'\[\e[01;36m\]$(my_git_ps1 ; my_hg_ps1 ; my_svn_ps1)\[\e[00m\]' PS1="$PS1"'\n\$ ' @@ -140,11 +140,10 @@ PS1="$PS1"'\n\$ ' ################################# function print_exit_code { - _exit_msg="\\033[01;33mexit code: $?\\033[00m" + local exit_msg="\e[01;33mexit code: $?\e[00m" if [ -z "${BASH_SOURCE[1]}" ]; then - echo -e "$_exit_msg" + echo -e "$exit_msg" fi - unset _exit_msg } trap print_exit_code ERR @@ -291,12 +290,12 @@ fi # xterm titlebar # ################## -# When at a prompt display `hostname:workingdir` +# When at a prompt display `workingdir (hostname)` function print_title_prompt { - echo -ne "\\033]0;$(hostname|cut -d. -f1):${PWD/$HOME/\~}\\007" + echo -ne "\e]0;bash:${PWD/$HOME/\~} ($(hostname -s))\a" if [[ "$TERM" == screen* ]]; then - echo -ne '\033kbash\033\\' + echo -ne '\ekbash\e\\' fi } PROMPT_COMMAND=print_title_prompt @@ -306,17 +305,18 @@ PROMPT_COMMAND=print_title_prompt function print_title_exec { [ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return - echo -ne '\033]0;' + echo -ne '\e]0;' echo -n "$BASH_COMMAND" | tr -cd '[:graph:] ' - echo -ne '\007' + echo -n " ($(hostname -s))" + echo -ne '\a' if [[ "$TERM" == screen* ]]; then - echo -ne '\033k' + echo -ne '\ek' echo -n "$BASH_COMMAND" | \ sed 's/^sudo //' | \ cut -d' ' -f1 | \ tr -cd '[:graph:]' - echo -ne '\033\\' + echo -ne '\e\\' fi } trap print_title_exec DEBUG -- 2.39.2