General cleanup, and put everything through shellcheck

This commit is contained in:
David Thurstenson 2019-05-15 23:17:05 -05:00
parent 54ebcdd409
commit e9165f2949
7 changed files with 37 additions and 13 deletions

10
.bashrc
View File

@ -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:' 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 # 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 # 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 [[ -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/ # Source all *.sh files in ~/.bashrc.d/
# This way all my useful little utilities are easier to reference and fix # 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 # Source a local bashrc if it exists. This gives the ability to insert untracked
# modifications to this .bashrc # modifications to this .bashrc
# shellcheck source=/dev/null
[[ -s ~/.local.bashrc ]] && source ~/.local.bashrc [[ -s ~/.local.bashrc ]] && source ~/.local.bashrc

View File

@ -1,6 +1,13 @@
countdown() { countdown() {
if [ -z "$1" ]; then
printf "
countdown: Count down while printing progress on the terminal
Usage: countdown <seconds>
"
fi
local secs="$1" local secs="$1"
while [ $secs -gt 0 ]; do while [ "$secs" -gt 0 ]; do
echo -ne "$secs\033[0K\r" echo -ne "$secs\033[0K\r"
sleep 1 sleep 1
: $((secs--)) : $((secs--))

View File

@ -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" printf "E: only one character accepted"
fi fi
local glyph=$1 local glyph=$1

View File

@ -1,3 +1,6 @@
# shellcheck disable=SC2120
# shellcheck disable=SC2119
# Print Dell Service Tag # Print Dell Service Tag
getdst() { getdst() {
if [[ "$1" = "-l" ]]; then if [[ "$1" = "-l" ]]; then

View File

@ -1,3 +1,5 @@
# shellcheck disable=SC2016
promptsetup() { promptsetup() {
# Color definitions for prompt # Color definitions for prompt
local fg_brightred='\[$(tput setaf 9)\]' local fg_brightred='\[$(tput setaf 9)\]'
@ -16,7 +18,7 @@ promptsetup() {
[ -n "$SSH_CLIENT" ] && hostname="${fg_brightred}\h${reset}" [ -n "$SSH_CLIENT" ] && hostname="${fg_brightred}\h${reset}"
# If in a python venv, add venv name in green. # 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. # If in a vcsh repo env, add repo name in magenta.
[ -n "$VCSH_REPO_NAME" ] && mixin=" ${fg_magenta}$VCSH_REPO_NAME${reset}" [ -n "$VCSH_REPO_NAME" ] && mixin=" ${fg_magenta}$VCSH_REPO_NAME${reset}"

View File

@ -1,13 +1,14 @@
# Screenshot utils
shot() { shot() {
# Usage: shot XY # Usage: shot XY
local destdir="$HOME/Pictures/screenshots" local destdir="$HOME/Pictures/screenshots"
local fname="shot-$(date +%F-%T).png" local fname
local pb="fb" local pb="fb"
local paste msgt msgd opts local paste msgt msgd opts
fname="shot-$(date +%F-%T).png"
if [ -z "$1" ]; then if [ -z "$1" ]; then
printf "Usage: shot XY printf "
Usage: shot XY
X: Target X: Target
Y: Destination Y: Destination
@ -38,7 +39,7 @@ p Upload to a pastebin (defined in function)
msgt="mouse selection" msgt="mouse selection"
;; ;;
*) printf "Unknown target: %s\n" "${1:0:1}" *) printf "Invalid target: %s\n" "${1:0:1}"
return return
;; ;;
esac esac
@ -52,7 +53,7 @@ p Upload to a pastebin (defined in function)
msgd="pastebin" msgd="pastebin"
paste=1;; paste=1;;
*) printf "Unknown destination: %s\n" "${1:1:1}" *) printf "Invalid destination: %s\n" "${1:1:1}"
return return
;; ;;
esac esac
@ -60,11 +61,13 @@ p Upload to a pastebin (defined in function)
# Make sure destination directory will exist # Make sure destination directory will exist
[[ ! -d "$destdir" ]] && mkdir -p "$destdir" [[ ! -d "$destdir" ]] && mkdir -p "$destdir"
local fpath="${destdir}/${fname}" local fpath="${destdir}/${fname}"
# If target is active window, give a 5 second countdown before running maim # If target is active window, give a 5 second countdown before running maim
[[ "$msgt" = "active window" ]] && countdown 5 [[ "$msgt" = "active window" ]] && countdown 5
maim $opts "$fpath" maim "$opts" "$fpath"
printf "Captured %s -> %s\n" "$msgt" "$msgd" printf "Captured %s -> %s\n" "$msgt" "$msgd"
# If destination is a pastebin, do the needful # If destination is a pastebin, do the needful
[[ "$paste" ]] && $pb "$fpath" [[ "$paste" ]] && $pb "$fpath"
} }

View File

@ -1,8 +1,10 @@
# shellcheck disable=SC1090
vactivate() { vactivate() {
local path=~/.venv/$1 local path=~/.venv/$1
if [[ ! -d $path ]]; then 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 fi
source $path/bin/activate; bash; deactivate source "$path"/bin/activate; bash; deactivate
} }