Fixes based on shellcheck output

This commit is contained in:
Fernando Schauenburg 2019-11-01 01:53:14 +01:00
parent 2d468f2070
commit 3a90bdad1f

View file

@ -25,12 +25,14 @@ 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
if [ "$(uname)" == "Darwin" ]; then if [ "$(uname)" == "Darwin" ]; then
# shellcheck disable=SC2123 # intentionally clearing the PATH here
PATH="" PATH=""
# shellcheck disable=SC1091 # /etc/profile is part of macOS
source /etc/profile source /etc/profile
fi fi
# Add custom bin dirs to PATH if they exist and are not already in PATH. # Add custom bin dirs to PATH if they exist and are not already in PATH.
while read bindir; do while read -r bindir; do
if [ -d "$bindir" ] && [[ ":$PATH:" != *":$bindir:"* ]]; then if [ -d "$bindir" ] && [[ ":$PATH:" != *":$bindir:"* ]]; then
PATH="$bindir:$PATH" PATH="$bindir:$PATH"
fi fi
@ -46,8 +48,9 @@ EOS
# Prepend custom man directories to MANPATH if they exist, so that we get # Prepend custom man directories to MANPATH if they exist, so that we get
# correct man page entries when multiple versions of a command are # correct man page entries when multiple versions of a command are
# available. # available.
export MANPATH=$(MANPATH= manpath) export MANPATH
while read mandir; do MANPATH=$(MANPATH='' manpath)
while read -r mandir; do
if [ -d "$mandir" ] && [[ ":$MANPATH:" != *":$mandir:"* ]]; then if [ -d "$mandir" ] && [[ ":$MANPATH:" != *":$mandir:"* ]]; then
MANPATH="$mandir:$MANPATH" MANPATH="$mandir:$MANPATH"
fi fi
@ -75,40 +78,43 @@ HISTSIZE=
HISTTIMEFORMAT="[%F %T] " HISTTIMEFORMAT="[%F %T] "
HISTFILE=~/.bash_eternal_history HISTFILE=~/.bash_eternal_history
# Color definitions (from http://ethanschoonover.com/solarized) # shellcheck disable=SC2034 # these variable are meant for use in shell only
# NAME RGB HEX SGR ANSI TERMCOL XTERM/HEX L*A*B RGB HSB {
# ---- ------- --- ---- ------- ----------- ----------- ----------- ----------- # Color definitions (from http://ethanschoonover.com/solarized)
Base03=8 Base03_RGB="002B36" # 1;30 8 brblack 234 #1c1c1c 15 -12 -12 0 43 54 193 100 21 # NAME RGB HEX SGR ANSI TERMCOL XTERM/HEX L*A*B RGB HSB
Base02=0 Base02_RGB="073642" # 0;30 0 black 235 #262626 20 -12 -12 7 54 66 192 90 26 # ---- ------- --- ---- ------- ----------- ----------- ----------- -----------
Base01=10 Base01_RGB="586E75" # 1;32 10 brgreen 240 #585858 45 -07 -07 88 110 117 194 25 46 Base03=8 Base03_RGB="002B36" # 1;30 8 brblack 234 #1c1c1c 15 -12 -12 0 43 54 193 100 21
Base00=11 Base00_RGB="657B83" # 1;33 11 bryellow 241 #626262 50 -07 -07 101 123 131 195 23 51 Base02=0 Base02_RGB="073642" # 0;30 0 black 235 #262626 20 -12 -12 7 54 66 192 90 26
Base0=12 Base0_RGB="839496" # 1;34 12 brblue 244 #808080 60 -06 -03 131 148 150 186 13 59 Base01=10 Base01_RGB="586E75" # 1;32 10 brgreen 240 #585858 45 -07 -07 88 110 117 194 25 46
Base1=14 Base1_RGB="93A1A1" # 1;36 14 brcyan 245 #8a8a8a 65 -05 -02 147 161 161 180 9 63 Base00=11 Base00_RGB="657B83" # 1;33 11 bryellow 241 #626262 50 -07 -07 101 123 131 195 23 51
Base2=7 Base2_RGB="EEE8D5" # 0;37 7 white 254 #e4e4e4 92 -00 10 238 232 213 44 11 93 Base0=12 Base0_RGB="839496" # 1;34 12 brblue 244 #808080 60 -06 -03 131 148 150 186 13 59
Base3=15 Base3_RGB="FDF6E3" # 1;37 15 brwhite 230 #ffffd7 97 00 10 253 246 227 44 10 99 Base1=14 Base1_RGB="93A1A1" # 1;36 14 brcyan 245 #8a8a8a 65 -05 -02 147 161 161 180 9 63
Yellow=3 Yellow_RGB="B58900" # 0;33 3 yellow 136 #af8700 60 10 65 181 137 0 45 100 71 Base2=7 Base2_RGB="EEE8D5" # 0;37 7 white 254 #e4e4e4 92 -00 10 238 232 213 44 11 93
Orange=9 Orange_RGB="CB4B16" # 1;31 9 brred 166 #d75f00 50 50 55 203 75 22 18 89 80 Base3=15 Base3_RGB="FDF6E3" # 1;37 15 brwhite 230 #ffffd7 97 00 10 253 246 227 44 10 99
Red=1 Red_RGB="DC322F" # 0;31 1 red 160 #d70000 50 65 45 220 50 47 1 79 86 Yellow=3 Yellow_RGB="B58900" # 0;33 3 yellow 136 #af8700 60 10 65 181 137 0 45 100 71
Magenta=5 Magenta_RGB="D33682" # 0;35 5 magenta 125 #af005f 50 65 -05 211 54 130 331 74 83 Orange=9 Orange_RGB="CB4B16" # 1;31 9 brred 166 #d75f00 50 50 55 203 75 22 18 89 80
Violet=13 Violet_RGB="6C71C4" # 1;35 13 brmagenta 61 #5f5faf 50 15 -45 108 113 196 237 45 77 Red=1 Red_RGB="DC322F" # 0;31 1 red 160 #d70000 50 65 45 220 50 47 1 79 86
Blue=4 Blue_RGB="268BD2" # 0;34 4 blue 33 #0087ff 55 -10 -45 38 139 210 205 82 82 Magenta=5 Magenta_RGB="D33682" # 0;35 5 magenta 125 #af005f 50 65 -05 211 54 130 331 74 83
Cyan=6 Cyan_RGB="2AA198" # 0;36 6 cyan 37 #00afaf 60 -35 -05 42 161 152 175 74 63 Violet=13 Violet_RGB="6C71C4" # 1;35 13 brmagenta 61 #5f5faf 50 15 -45 108 113 196 237 45 77
Green=2 Green_RGB="859900" # 0;32 2 green 64 #5f8700 60 -20 65 133 153 0 68 100 60 Blue=4 Blue_RGB="268BD2" # 0;34 4 blue 33 #0087ff 55 -10 -45 38 139 210 205 82 82
Cyan=6 Cyan_RGB="2AA198" # 0;36 6 cyan 37 #00afaf 60 -35 -05 42 161 152 175 74 63
Green=2 Green_RGB="859900" # 0;32 2 green 64 #5f8700 60 -20 65 133 153 0 68 100 60
PS1_DEFAULT=$(tput setaf $Cyan) # user@host color for local sessions PS1_DEFAULT=$(tput setaf $Cyan) # user@host color for local sessions
PS1_SSH=$(tput setaf $Yellow) # user@host color in SSH session PS1_SSH=$(tput setaf $Yellow) # user@host color in SSH session
PS1_ROOT=$(tput setaf $Orange) # user@host color if logged in as root PS1_ROOT=$(tput setaf $Orange) # user@host color if logged in as root
PS1_PWD=$(tput setaf $Blue) # PWD color PS1_PWD=$(tput setaf $Blue) # PWD color
PS1_ERR=$(tput setaf $Red) # color for last exit code if non-zero PS1_ERR=$(tput setaf $Red) # color for last exit code if non-zero
PS1_GIT=$(tput setaf $Green) # color for git branch PS1_GIT=$(tput setaf $Green) # color for git branch
PS1_VENV=$(tput setaf $Violet) # color for python virtual env PS1_VENV=$(tput setaf $Violet) # color for python virtual env
PS1_JOBS=$(tput setaf $Magenta) # color for background jobs PS1_JOBS=$(tput setaf $Magenta) # color for background jobs
PS1_RST=$(tput sgr0) PS1_RST=$(tput sgr0)
GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM=verbose GIT_PS1_SHOWUPSTREAM=verbose
}
PS2="... " PS2="... "
@ -116,21 +122,26 @@ PROMPT_COMMAND=__ps1_set
__ps1_set() { __ps1_set() {
local last_status=$? local last_status=$?
local prompt color sep_color sep
if [ $EUID -eq 0 ]; then if [ $EUID -eq 0 ]; then
local prompt=$(printf '#%.0s' $(seq 1 $SHLVL)) prompt=$(printf '#%.0s' $(seq 1 $SHLVL))
local color=$PS1_ROOT color=$PS1_ROOT
else else
local prompt=$(printf '\$%.0s' $(seq 1 $SHLVL)) prompt=$(printf '\$%.0s' $(seq 1 $SHLVL))
if [ -n "$SSH_CLIENT" ]; then if [ -n "$SSH_CLIENT" ]; then
local color=$PS1_SSH color=$PS1_SSH
else else
local color=$PS1_DEFAULT color=$PS1_DEFAULT
fi fi
fi fi
local sep_color=$(tput setaf $Base01) if [ "$BACKGROUND" = "light" ]; then
if [ "$BACKGROUND" = "light" ]; then sep_color=$(tput setaf $Base1); fi sep_color=$(tput setaf $Base1)
local sep="$sep_color > $PS1_RST" else
sep_color=$(tput setaf $Base01)
fi
sep="$sep_color > $PS1_RST"
PS1="\n" PS1="\n"
if [ $last_status -ne 0 ]; then if [ $last_status -ne 0 ]; then
@ -144,13 +155,17 @@ __ps1_set() {
} }
__ps1_venv() { __ps1_venv() {
local venv="$(basename "$VIRTUAL_ENV" 2>/dev/null)" local venv
[ ! -z "$venv" ] && printf "${1:-%s}" "$venv" venv="$(basename "$VIRTUAL_ENV" 2>/dev/null)"
# shellcheck disable=SC2059 # variable format string is really needed here
[ -n "$venv" ] && printf "${1:-%s}" "$venv"
} }
__ps1_jobs() { __ps1_jobs() {
local n=$(jobs | wc -l) local n
[ $n -gt 0 ] && printf "${1:-%s}" "$n job$([ $n -gt 1 ] && echo -n s)" n=$(jobs | wc -l)
# shellcheck disable=SC2059 # variable format string is really needed here
[ "$n" -gt 0 ] && printf "${1:-%s}" "$n job$([ "$n" -gt 1 ] && echo -n s)"
} }
############################################################################## ##############################################################################
@ -202,15 +217,18 @@ _send_osc() {
} }
_update_colors() { _update_colors() {
local cursor fg bg n rgb
export BACKGROUND="$1" export BACKGROUND="$1"
local cursor=$Red_RGB fg=$Base1_RGB bg=$Base03_RGB cursor=$Red_RGB
if [ $BACKGROUND = light ]; then fg=$Base01_RGB; bg=$Base3_RGB; fi if [ "$BACKGROUND" = "light" ]; then fg=$Base01_RGB; bg=$Base3_RGB
else fg=$Base1_RGB; bg=$Base03_RGB
fi
local n rgb comment
if [ -n "$ITERM_SESSION_ID" ] if [ -n "$ITERM_SESSION_ID" ]
then # iTerm2 then # iTerm2
while read n rgb comment; 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
2 $Green_RGB 2 $Green_RGB
@ -227,16 +245,16 @@ _update_colors() {
d $Violet_RGB d $Violet_RGB
e $Base1_RGB e $Base1_RGB
f $Base3_RGB f $Base3_RGB
g $fg Foreground g $fg
h $bg Background h $bg
i $fg Bold i $fg
j $Base01_RGB Selection j $Base01_RGB
k $Base2_RGB Selected text k $Base2_RGB
l $cursor Cursor l $cursor
m $cursor Cursor text m $cursor
EOL EOL
else # assume xterm else # assume xterm
while read n rgb comment; 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
2 $Green_RGB 2 $Green_RGB
@ -254,10 +272,10 @@ EOL
14 $Base1_RGB 14 $Base1_RGB
15 $Base3_RGB 15 $Base3_RGB
EOL EOL
while read n rgb comment; do _send_osc "$n;#$rgb"; done <<EOL while read -r n rgb; do _send_osc "$n;#$rgb"; done <<EOL
10 $fg Foreground 10 $fg
11 $bg Background 11 $bg
12 $cursor Cursor 12 $cursor
EOL EOL
fi fi
@ -267,8 +285,8 @@ EOL
fi fi
local ls_colors="$HOME/.config/dircolors/solarized-$BACKGROUND" local ls_colors="$HOME/.config/dircolors/solarized-$BACKGROUND"
if type dircolors &>/dev/null && [ -f $ls_colors ]; then if type dircolors &>/dev/null && [ -f "$ls_colors" ]; then
eval "$(dircolors $ls_colors)" eval "$(dircolors "$ls_colors")"
fi fi
} }
@ -281,18 +299,21 @@ tree() { command tree --dirsfirst -FI '.git|Spotlight-V100|.fseventsd' "$@"; }
ltree() { tree -C "$@" | less -R; } ltree() { tree -C "$@" | less -R; }
# Combined mkdir and cd # Combined mkdir and cd
mkcd() { mkdir -p -- "$1" && cd -P -- "$1"; } mkcd() { mkdir -p -- "$1" && cd -P -- "$1" || return; }
# Colorized `man` # Colorized `man`
man() { man() {
local rst=$(tput sgr0) local rst standout bold underline
local standout=$(tput -S <<<$(echo -e "setaf $Base03\nsetab $Cyan"))
local bold=$(tput -S <<<$(echo -e "setaf $Yellow")) rst=$(tput sgr0)
local underline=$(tput -S <<<$(echo -e "setaf $Base3\nsmul")) if [ "$BACKGROUND" = "light" ]; then
if [ $BACKGROUND = light ]; then standout=$(tput -S <<<"$(echo -e "setaf $Base3\nsetab $Cyan")")
standout=$(tput -S <<<$(echo -e "setaf $Base3\nsetab $Cyan")) bold=$(tput -S <<<"$(echo -e "setaf $Blue")")
bold=$(tput -S <<<$(echo -e "setaf $Blue")) underline=$(tput -S <<<"$(echo -e "setaf $Base02\nsmul")")
underline=$(tput -S <<<$(echo -e "setaf $Base02\nsmul")) else
standout=$(tput -S <<<"$(echo -e "setaf $Base03\nsetab $Cyan")")
bold=$(tput -S <<<"$(echo -e "setaf $Yellow")")
underline=$(tput -S <<<"$(echo -e "setaf $Base3\nsmul")")
fi fi
LESS_TERMCAP_so=$standout \ LESS_TERMCAP_so=$standout \
@ -306,25 +327,30 @@ man() {
} }
solarized() { solarized() {
local name rst=$(tput sgr0) local rst name name_rgb rgb fg bg
rst=$(tput sgr0)
for name in Red Orange Yellow Green Cyan Blue Violet Magenta Base{0{3..0},{0..3}} for name in Red Orange Yellow Green Cyan Blue Violet Magenta Base{0{3..0},{0..3}}
do do
local name_rgb=${name}_RGB name_rgb=${name}_RGB
local i=${!name} rgb=${!name_rgb} i=
local fg=$(tput setaf $i) bg=$(tput setab $i) rgb=${!name_rgb}
printf "$bg%6s$rst $fg#$rgb %2d $name$rst\n" '' $i fg=$(tput setaf "${!name}")
bg=$(tput setab "${!name}")
printf "$bg%6s$rst $fg#$rgb %2d $name$rst\n" '' "${!name}"
done done
} }
# Print all 256 colors # Print all 256 colors
colortest() { colortest() {
local i j rst=$(tput sgr0) local i j rst
rst=$(tput sgr0)
for i in $(seq 0 15); do for i in $(seq 0 15); do
for j in $(seq 0 15); do for j in $(seq 0 15); do
local n=$(( 16 * $i + $j )) local n=$(( 16 * i + j ))
printf "$(tput setab $n) %3d " $n printf "$(tput setab $n) %3d " $n
done done
echo $rst echo "$rst"
done done
} }
@ -338,6 +364,7 @@ _update_colors "${BACKGROUND:-dark}"
# Enable available completion helpers # Enable available completion helpers
if [ -d /usr/local/etc/bash_completion.d ]; then if [ -d /usr/local/etc/bash_completion.d ]; then
for completion in /usr/local/etc/bash_completion.d/*; do for completion in /usr/local/etc/bash_completion.d/*; do
# shellcheck disable=SC1090
source "$completion" source "$completion"
done done
unset completion unset completion
@ -345,6 +372,7 @@ fi
# Source a local bashrc if available # Source a local bashrc if available
if [ -f "$HOME/.bashrc.local" ]; then if [ -f "$HOME/.bashrc.local" ]; then
# shellcheck disable=SC1090
source "$HOME/.bashrc.local" source "$HOME/.bashrc.local"
fi fi