diff --git a/.bashrc b/.bashrc index 60ab6e6..9fe3892 100644 --- a/.bashrc +++ b/.bashrc @@ -21,7 +21,11 @@ shopt -s autocd export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:' # Prefer vim, but if it's not installed, nano will do -[[ -s /usr/bin/vim ]] && export EDITOR=vim || export EDITOR=nano +if [[ -s /usr/bin/vim ]]; then + export EDITOR=vim +else + export EDITOR=nano +fi # Enable pkgfile to automatically search for packages if pkgfile is installed [[ -s /usr/share/doc/pkgfile/command-not-found.bash ]] && source /usr/share/doc/pkgfile/command-not-found.bash @@ -31,9 +35,11 @@ export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43 # Source all *.sh files in ~/.bashrc.d/ # This way all my useful little utilities are easier to reference and fix -for f in ~/.bashrc.d/*.sh; do source $f; done +# shellcheck source=/dev/null +for f in ~/.bashrc.d/*.sh; do source "$f"; done # Source a local bashrc if it exists. This gives the ability to insert untracked # modifications to this .bashrc +# shellcheck source=/dev/null [[ -s ~/.local.bashrc ]] && source ~/.local.bashrc diff --git a/.bashrc.d/countdown.sh b/.bashrc.d/countdown.sh index bf1aa0d..023fa28 100644 --- a/.bashrc.d/countdown.sh +++ b/.bashrc.d/countdown.sh @@ -1,6 +1,13 @@ countdown() { + if [ -z "$1" ]; then + printf " +countdown: Count down while printing progress on the terminal + +Usage: countdown +" + fi local secs="$1" - while [ $secs -gt 0 ]; do + while [ "$secs" -gt 0 ]; do echo -ne "$secs\033[0K\r" sleep 1 : $((secs--)) diff --git a/.bashrc.d/fontfind.sh b/.bashrc.d/fontfind.sh index 4ae60ec..d01940f 100644 --- a/.bashrc.d/fontfind.sh +++ b/.bashrc.d/fontfind.sh @@ -1,4 +1,5 @@ -fontfind() { if [[ -z $1 || ${#1} -gt 1 ]]; then +fontfind() { + if [[ -z $1 || ${#1} -gt 1 ]]; then printf "E: only one character accepted" fi local glyph=$1 diff --git a/.bashrc.d/getdst.sh b/.bashrc.d/getdst.sh index 03a6386..431ee69 100644 --- a/.bashrc.d/getdst.sh +++ b/.bashrc.d/getdst.sh @@ -1,3 +1,6 @@ +# shellcheck disable=SC2120 +# shellcheck disable=SC2119 + # Print Dell Service Tag getdst() { if [[ "$1" = "-l" ]]; then diff --git a/.bashrc.d/prompt.sh b/.bashrc.d/prompt.sh index 21f9c5c..5052b85 100644 --- a/.bashrc.d/prompt.sh +++ b/.bashrc.d/prompt.sh @@ -1,3 +1,5 @@ +# shellcheck disable=SC2016 + promptsetup() { # Color definitions for prompt local fg_brightred='\[$(tput setaf 9)\]' @@ -16,7 +18,7 @@ promptsetup() { [ -n "$SSH_CLIENT" ] && hostname="${fg_brightred}\h${reset}" # If in a python venv, add venv name in green. - [ -n "$VIRTUAL_ENV" ] && mixin=" ${fg_green}$(basename $VIRTUAL_ENV)${reset}" + [ -n "$VIRTUAL_ENV" ] && mixin=" ${fg_green}$(basename "$VIRTUAL_ENV")${reset}" # If in a vcsh repo env, add repo name in magenta. [ -n "$VCSH_REPO_NAME" ] && mixin=" ${fg_magenta}$VCSH_REPO_NAME${reset}" diff --git a/.bashrc.d/shot.sh b/.bashrc.d/shot.sh index eed2745..de9ae21 100644 --- a/.bashrc.d/shot.sh +++ b/.bashrc.d/shot.sh @@ -1,13 +1,14 @@ -# Screenshot utils shot() { # Usage: shot XY local destdir="$HOME/Pictures/screenshots" - local fname="shot-$(date +%F-%T).png" + local fname local pb="fb" local paste msgt msgd opts + fname="shot-$(date +%F-%T).png" if [ -z "$1" ]; then - printf "Usage: shot XY + printf " +Usage: shot XY X: Target Y: Destination @@ -38,7 +39,7 @@ p Upload to a pastebin (defined in function) msgt="mouse selection" ;; - *) printf "Unknown target: %s\n" "${1:0:1}" + *) printf "Invalid target: %s\n" "${1:0:1}" return ;; esac @@ -52,7 +53,7 @@ p Upload to a pastebin (defined in function) msgd="pastebin" paste=1;; - *) printf "Unknown destination: %s\n" "${1:1:1}" + *) printf "Invalid destination: %s\n" "${1:1:1}" return ;; esac @@ -60,11 +61,13 @@ p Upload to a pastebin (defined in function) # Make sure destination directory will exist [[ ! -d "$destdir" ]] && mkdir -p "$destdir" local fpath="${destdir}/${fname}" + # If target is active window, give a 5 second countdown before running maim [[ "$msgt" = "active window" ]] && countdown 5 - maim $opts "$fpath" + maim "$opts" "$fpath" printf "Captured %s -> %s\n" "$msgt" "$msgd" + # If destination is a pastebin, do the needful [[ "$paste" ]] && $pb "$fpath" } diff --git a/.bashrc.d/vactivate.sh b/.bashrc.d/vactivate.sh index b4d83c0..36bd0d1 100644 --- a/.bashrc.d/vactivate.sh +++ b/.bashrc.d/vactivate.sh @@ -1,8 +1,10 @@ +# shellcheck disable=SC1090 + vactivate() { local path=~/.venv/$1 if [[ ! -d $path ]]; then - python -m venv --prompt "venv: $1" --system-site-packages $path + python -m venv --prompt "venv: $1" --system-site-packages "$path" fi - source $path/bin/activate; bash; deactivate + source "$path"/bin/activate; bash; deactivate }