From 7b1c37926efefac5369c1b856802d40a4e235e66 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 16 Jan 2024 10:04:13 +0100 Subject: [PATCH] Halving .bashrc load time. --- .bashrc | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/.bashrc b/.bashrc index 95b359c..95aab9c 100644 --- a/.bashrc +++ b/.bashrc @@ -21,11 +21,6 @@ umask 022 CDPATH="~/src/" -if [ -n "$DISPLAY" ] -then - xset b off -fi - # http://nion.modprobe.de/blog/archives/572-less-colors-for-man-pages.html export LESS_TERMCAP_mb=$'\E[01;31m' # debut de blink export LESS_TERMCAP_md=$'\E[01;31m' # debut de gras @@ -51,7 +46,7 @@ alias ls='ls --color=auto' alias fingerprint='find /etc/ssh -name "*.pub" -exec ssh-keygen -l -f {} \;' alias rekey='ssh-add -e /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so >/dev/null 2>&1; ssh-add -s /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so' -while read -r _ _ dest src +while read -r _ _ dest src # costs 9ms do if [[ (! -f "$HOME/$dest") || $(( RANDOM % 100 )) == 0 ]] then @@ -64,7 +59,7 @@ do done < <(grep '^# Download ' $HOME/.bashrc) unset dest src -. /etc/bash_completion +. /etc/bash_completion # costs 6ms if [[ "$TERM" != 'dumb' ]] then @@ -72,25 +67,9 @@ then else _TITLE='' fi + _PREV_FAIL="\`PREV_FAIL=\$?; if [ \$PREV_FAIL != 0 ]; then echo \[\e[31m\]\$PREV_FAIL \[\e[0m\]; fi\`" -GIT_RED_FG='\e[38;2;244;77;39m' -GIT_RED_BG='\e[48;2;244;77;39m' -PY_BLUE_FG='\e[38;2;53;112;160m' -PY_BLUE_BG='\e[48;2;53;112;160m' -PY_YELLOW_FG='\e[38;2;255;222;87m' - -HOSTNAME_SUM=$(cksum <(hostname) | cut -d' ' -f1) -HOSTNAME_BOLD=$(( ($HOSTNAME_SUM + 1) % 2)) -HOSTNAME_HUE=$(( ($HOSTNAME_SUM + 3) % 6 + 31)) - -USERNAME_SUM=$(($(cksum <(whoami) | cut -d' ' -f1) + 5)) # + 5 so root gots red. -USERNAME_BOLD=$(( ($USERNAME_SUM + 1) % 2)) -USERNAME_HUE=$(( ($USERNAME_SUM + 2) % 6 + 31)) - -HOSTNAME_COLOR=$'\E'"[$HOSTNAME_BOLD;${HOSTNAME_HUE}m" -USERNAME_COLOR=$'\E'"[$USERNAME_BOLD;${USERNAME_HUE}m" - git_prompt() { # Wrapper around __git_ps1 @@ -101,6 +80,13 @@ git_prompt() fi } +GIT_RED_FG='\e[38;2;244;77;39m' +GIT_RED_BG='\e[48;2;244;77;39m' +PY_BLUE_FG='\e[38;2;53;112;160m' +PY_BLUE_BG='\e[48;2;53;112;160m' +PY_YELLOW_FG='\e[38;2;255;222;87m' +HOSTNAME_COLOR=$'\E[1;34m' +USERNAME_COLOR=$'\E[1;35m' PY_PS1='$(python_prompt "${PY_BLUE_FG}🭮${PY_BLUE_BG}${PY_YELLOW_FG}  %s \e[0m${PY_BLUE_FG}🭬\e[0m")' GIT_PS1='$(git_prompt "${GIT_RED_FG}🭮${GIT_RED_BG}\e[97m  %s \e[0m${GIT_RED_FG}🭬\e[0m")' PS1="${_TITLE}${_PREV_FAIL}${USERNAME_COLOR}\u\e[0m@${HOSTNAME_COLOR}\H\e[0m:\e[32m\w\e[0m${PY_PS1}${GIT_PS1}\n\$ " @@ -123,5 +109,3 @@ venv() printf "VIRTUAL_ENV=.venv\nlayout python3\n" > .envrc direnv allow . } - -mkdir -p ~/.cache/ssh/ # See .ssh/config/, it's for ControlPath.