Fixes based on shellcheck output
This commit is contained in:
parent
2d468f2070
commit
3a90bdad1f
1 changed files with 110 additions and 82 deletions
128
dotfiles/.bashrc
128
dotfiles/.bashrc
|
@ -25,12 +25,14 @@ fi
|
|||
# Prevent path_helper from messing with the PATH when starting tmux.
|
||||
# See: https://superuser.com/a/583502
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
# shellcheck disable=SC2123 # intentionally clearing the PATH here
|
||||
PATH=""
|
||||
# shellcheck disable=SC1091 # /etc/profile is part of macOS
|
||||
source /etc/profile
|
||||
fi
|
||||
|
||||
# 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
|
||||
PATH="$bindir:$PATH"
|
||||
fi
|
||||
|
@ -46,8 +48,9 @@ EOS
|
|||
# Prepend custom man directories to MANPATH if they exist, so that we get
|
||||
# correct man page entries when multiple versions of a command are
|
||||
# available.
|
||||
export MANPATH=$(MANPATH= manpath)
|
||||
while read mandir; do
|
||||
export MANPATH
|
||||
MANPATH=$(MANPATH='' manpath)
|
||||
while read -r mandir; do
|
||||
if [ -d "$mandir" ] && [[ ":$MANPATH:" != *":$mandir:"* ]]; then
|
||||
MANPATH="$mandir:$MANPATH"
|
||||
fi
|
||||
|
@ -75,6 +78,8 @@ HISTSIZE=
|
|||
HISTTIMEFORMAT="[%F %T] "
|
||||
HISTFILE=~/.bash_eternal_history
|
||||
|
||||
# shellcheck disable=SC2034 # these variable are meant for use in shell only
|
||||
{
|
||||
# Color definitions (from http://ethanschoonover.com/solarized)
|
||||
# NAME RGB HEX SGR ANSI TERMCOL XTERM/HEX L*A*B RGB HSB
|
||||
# ---- ------- --- ---- ------- ----------- ----------- ----------- -----------
|
||||
|
@ -109,6 +114,7 @@ GIT_PS1_SHOWDIRTYSTATE=1
|
|||
GIT_PS1_SHOWSTASHSTATE=1
|
||||
GIT_PS1_SHOWUNTRACKEDFILES=1
|
||||
GIT_PS1_SHOWUPSTREAM=verbose
|
||||
}
|
||||
|
||||
PS2="... "
|
||||
|
||||
|
@ -116,21 +122,26 @@ PROMPT_COMMAND=__ps1_set
|
|||
|
||||
__ps1_set() {
|
||||
local last_status=$?
|
||||
local prompt color sep_color sep
|
||||
|
||||
if [ $EUID -eq 0 ]; then
|
||||
local prompt=$(printf '#%.0s' $(seq 1 $SHLVL))
|
||||
local color=$PS1_ROOT
|
||||
prompt=$(printf '#%.0s' $(seq 1 $SHLVL))
|
||||
color=$PS1_ROOT
|
||||
else
|
||||
local prompt=$(printf '\$%.0s' $(seq 1 $SHLVL))
|
||||
prompt=$(printf '\$%.0s' $(seq 1 $SHLVL))
|
||||
if [ -n "$SSH_CLIENT" ]; then
|
||||
local color=$PS1_SSH
|
||||
color=$PS1_SSH
|
||||
else
|
||||
local color=$PS1_DEFAULT
|
||||
color=$PS1_DEFAULT
|
||||
fi
|
||||
fi
|
||||
|
||||
local sep_color=$(tput setaf $Base01)
|
||||
if [ "$BACKGROUND" = "light" ]; then sep_color=$(tput setaf $Base1); fi
|
||||
local sep="$sep_color > $PS1_RST"
|
||||
if [ "$BACKGROUND" = "light" ]; then
|
||||
sep_color=$(tput setaf $Base1)
|
||||
else
|
||||
sep_color=$(tput setaf $Base01)
|
||||
fi
|
||||
sep="$sep_color > $PS1_RST"
|
||||
|
||||
PS1="\n"
|
||||
if [ $last_status -ne 0 ]; then
|
||||
|
@ -144,13 +155,17 @@ __ps1_set() {
|
|||
}
|
||||
|
||||
__ps1_venv() {
|
||||
local venv="$(basename "$VIRTUAL_ENV" 2>/dev/null)"
|
||||
[ ! -z "$venv" ] && printf "${1:-%s}" "$venv"
|
||||
local 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() {
|
||||
local n=$(jobs | wc -l)
|
||||
[ $n -gt 0 ] && printf "${1:-%s}" "$n job$([ $n -gt 1 ] && echo -n s)"
|
||||
local n
|
||||
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() {
|
||||
local cursor fg bg n rgb
|
||||
|
||||
export BACKGROUND="$1"
|
||||
|
||||
local cursor=$Red_RGB fg=$Base1_RGB bg=$Base03_RGB
|
||||
if [ $BACKGROUND = light ]; then fg=$Base01_RGB; bg=$Base3_RGB; fi
|
||||
cursor=$Red_RGB
|
||||
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" ]
|
||||
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
|
||||
1 $Red_RGB
|
||||
2 $Green_RGB
|
||||
|
@ -227,16 +245,16 @@ _update_colors() {
|
|||
d $Violet_RGB
|
||||
e $Base1_RGB
|
||||
f $Base3_RGB
|
||||
g $fg Foreground
|
||||
h $bg Background
|
||||
i $fg Bold
|
||||
j $Base01_RGB Selection
|
||||
k $Base2_RGB Selected text
|
||||
l $cursor Cursor
|
||||
m $cursor Cursor text
|
||||
g $fg
|
||||
h $bg
|
||||
i $fg
|
||||
j $Base01_RGB
|
||||
k $Base2_RGB
|
||||
l $cursor
|
||||
m $cursor
|
||||
EOL
|
||||
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
|
||||
1 $Red_RGB
|
||||
2 $Green_RGB
|
||||
|
@ -254,10 +272,10 @@ EOL
|
|||
14 $Base1_RGB
|
||||
15 $Base3_RGB
|
||||
EOL
|
||||
while read n rgb comment; do _send_osc "$n;#$rgb"; done <<EOL
|
||||
10 $fg Foreground
|
||||
11 $bg Background
|
||||
12 $cursor Cursor
|
||||
while read -r n rgb; do _send_osc "$n;#$rgb"; done <<EOL
|
||||
10 $fg
|
||||
11 $bg
|
||||
12 $cursor
|
||||
EOL
|
||||
fi
|
||||
|
||||
|
@ -267,8 +285,8 @@ EOL
|
|||
fi
|
||||
|
||||
local ls_colors="$HOME/.config/dircolors/solarized-$BACKGROUND"
|
||||
if type dircolors &>/dev/null && [ -f $ls_colors ]; then
|
||||
eval "$(dircolors $ls_colors)"
|
||||
if type dircolors &>/dev/null && [ -f "$ls_colors" ]; then
|
||||
eval "$(dircolors "$ls_colors")"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -281,18 +299,21 @@ tree() { command tree --dirsfirst -FI '.git|Spotlight-V100|.fseventsd' "$@"; }
|
|||
ltree() { tree -C "$@" | less -R; }
|
||||
|
||||
# Combined mkdir and cd
|
||||
mkcd() { mkdir -p -- "$1" && cd -P -- "$1"; }
|
||||
mkcd() { mkdir -p -- "$1" && cd -P -- "$1" || return; }
|
||||
|
||||
# Colorized `man`
|
||||
man() {
|
||||
local rst=$(tput sgr0)
|
||||
local standout=$(tput -S <<<$(echo -e "setaf $Base03\nsetab $Cyan"))
|
||||
local bold=$(tput -S <<<$(echo -e "setaf $Yellow"))
|
||||
local underline=$(tput -S <<<$(echo -e "setaf $Base3\nsmul"))
|
||||
if [ $BACKGROUND = light ]; then
|
||||
standout=$(tput -S <<<$(echo -e "setaf $Base3\nsetab $Cyan"))
|
||||
bold=$(tput -S <<<$(echo -e "setaf $Blue"))
|
||||
underline=$(tput -S <<<$(echo -e "setaf $Base02\nsmul"))
|
||||
local rst standout bold underline
|
||||
|
||||
rst=$(tput sgr0)
|
||||
if [ "$BACKGROUND" = "light" ]; then
|
||||
standout=$(tput -S <<<"$(echo -e "setaf $Base3\nsetab $Cyan")")
|
||||
bold=$(tput -S <<<"$(echo -e "setaf $Blue")")
|
||||
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
|
||||
|
||||
LESS_TERMCAP_so=$standout \
|
||||
|
@ -306,25 +327,30 @@ man() {
|
|||
}
|
||||
|
||||
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}}
|
||||
do
|
||||
local name_rgb=${name}_RGB
|
||||
local i=${!name} rgb=${!name_rgb}
|
||||
local fg=$(tput setaf $i) bg=$(tput setab $i)
|
||||
printf "$bg%6s$rst $fg#$rgb %2d $name$rst\n" '' $i
|
||||
name_rgb=${name}_RGB
|
||||
i=
|
||||
rgb=${!name_rgb}
|
||||
fg=$(tput setaf "${!name}")
|
||||
bg=$(tput setab "${!name}")
|
||||
printf "$bg%6s$rst $fg#$rgb %2d $name$rst\n" '' "${!name}"
|
||||
done
|
||||
}
|
||||
|
||||
# Print all 256 colors
|
||||
colortest() {
|
||||
local i j rst=$(tput sgr0)
|
||||
local i j rst
|
||||
rst=$(tput sgr0)
|
||||
for i 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
|
||||
done
|
||||
echo $rst
|
||||
echo "$rst"
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -338,6 +364,7 @@ _update_colors "${BACKGROUND:-dark}"
|
|||
# Enable available completion helpers
|
||||
if [ -d /usr/local/etc/bash_completion.d ]; then
|
||||
for completion in /usr/local/etc/bash_completion.d/*; do
|
||||
# shellcheck disable=SC1090
|
||||
source "$completion"
|
||||
done
|
||||
unset completion
|
||||
|
@ -345,6 +372,7 @@ fi
|
|||
|
||||
# Source a local bashrc if available
|
||||
if [ -f "$HOME/.bashrc.local" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
source "$HOME/.bashrc.local"
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue