# HG changeset patch # User Oleksandr Gavenko # Date 1546165608 -7200 # Node ID 691db6af02e450ddd35943579514fe3ca50d80ae # Parent 0dba496629c95ab9932d16566be4a0fe59b58335 Change rules size only on SIGWINCH. $COLUMNS isn't updated on SIGWINCH yet so "tput" is used. For better performance ruler is calculated by substring. Moving ruler handler to trap cleans console from garbage when "set -x" is set in interactive session. It is useful during debugging of bash completion. diff -r 0dba496629c9 -r 691db6af02e4 .bashrc --- a/.bashrc Sun Dec 30 12:21:48 2018 +0200 +++ b/.bashrc Sun Dec 30 12:26:48 2018 +0200 @@ -9,20 +9,24 @@ . ~/.env fi -_my_ruler() { - local ruler='' - for (( i=${COLUMNS:-78}; i>0; i-=1 )) do - ruler+='=' - done - echo $ruler +shopt -s checkwinsize +shopt -s promptvars + +_my_ruler_handler() { + local ruler='================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================' + local size=`tput cols` + ruler=${ruler:0:${size}} + _my_ruler=$ruler } +_my_ruler_handler +trap '_my_ruler_handler' SIGWINCH -PS1='\n$(_my_ruler)\r$?|\u@\h \w \nbash# ' +PS1='\n${_my_ruler}\r$?|\u@\h \w \nbash# ' PS2='> ' case "$TERM" in xterm*|eterm-color|screen|linux|cygwin) - PS1=$'\n\e[34m\e[1m$(_my_ruler)\r$?|\e[31m\u\e[35m@\h\e[0m\e[36m \w \n\[\e[1m\e[31m\]bash#\[\e[0m\] ' + PS1=$'\n\e[34m\e[1m${_my_ruler}\r$?|\e[31m\u\e[35m@\h\e[0m\e[36m \w \n\[\e[1m\e[31m\]bash#\[\e[0m\] ' PS2=$'\[\e[32m\]> \[\e[0m\]' ;; esac