Improve readability of if statements in bashrc

This commit is contained in:
Fernando Schauenburg 2019-11-01 01:58:53 +01:00
parent 3a90bdad1f
commit 16cd08905e

View file

@ -18,9 +18,7 @@ export PAGER=less
# installed (e.g. running on Linux), assume /usr/local for our # installed (e.g. running on Linux), assume /usr/local for our
# installations. # installations.
prefix=/usr/local prefix=/usr/local
if command -v brew &>/dev/null; then if command -v brew &>/dev/null; then prefix=$(brew --prefix); fi
prefix=$(brew --prefix)
fi
# Prevent path_helper from messing with the PATH when starting tmux. # Prevent path_helper from messing with the PATH when starting tmux.
# See: https://superuser.com/a/583502 # See: https://superuser.com/a/583502
@ -211,8 +209,14 @@ alias light='_update_colors light'
alias dark='_update_colors dark' alias dark='_update_colors dark'
_send_osc() { _send_osc() {
local OSC=$'\e]' ST=$'\e\\' local OSC ST
if [ -n "$TMUX" ]; then OSC=$'\ePtmux;\e\e]' ST=$'\e\e\\\e\\'; fi if [ -n "$TMUX" ]; then
OSC=$'\ePtmux;\e\e]'
ST=$'\e\e\\\e\\';
else
OSC=$'\e]'
ST=$'\e\\'
fi
echo -n "$OSC$1$ST" echo -n "$OSC$1$ST"
} }
@ -222,12 +226,15 @@ _update_colors() {
export BACKGROUND="$1" export BACKGROUND="$1"
cursor=$Red_RGB cursor=$Red_RGB
if [ "$BACKGROUND" = "light" ]; then fg=$Base01_RGB; bg=$Base3_RGB if [ "$BACKGROUND" = "light" ]; then
else fg=$Base1_RGB; bg=$Base03_RGB fg=$Base01_RGB
bg=$Base3_RGB
else
fg=$Base1_RGB
bg=$Base03_RGB
fi fi
if [ -n "$ITERM_SESSION_ID" ] if [ -n "$ITERM_SESSION_ID" ]; then # iTerm2
then # iTerm2
while read -r n rgb; do _send_osc "P$n$rgb"; done <<EOL while read -r n rgb; do _send_osc "P$n$rgb"; done <<EOL
0 $Base02_RGB 0 $Base02_RGB
1 $Red_RGB 1 $Red_RGB
@ -253,7 +260,7 @@ _update_colors() {
l $cursor l $cursor
m $cursor m $cursor
EOL EOL
else # assume xterm else # assume xterm
while read -r n rgb; do _send_osc "4;$n;#$rgb"; done <<EOL while read -r n rgb; do _send_osc "4;$n;#$rgb"; done <<EOL
0 $Base02_RGB 0 $Base02_RGB
1 $Red_RGB 1 $Red_RGB