diff --git a/sh/connect b/sh/connect index d0e721f..c37240d 100755 --- a/sh/connect +++ b/sh/connect @@ -1,36 +1,37 @@ #!/bin/sh -[ "$(ps -aux | grep -c NetworkManager)" -eq 2 ] && \ - printf "NetworkManager is already running!" && \ +[ "$(pgrep -c NetworkManager)" -eq 1 ] && + printf "NetworkManager is already running!\n" && exit case $1 in "c"*) wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B dhcpcd wlp3s0 - tor & disown + # make tor and nohup shut up in a posix-compliant way + nohup tor >/dev/null 2>&1 ;; "d"*) killall -15 wpa_supplicant dhcpcd tor ;; "r"*) - sh $0 d - sh $0 c + sh "$0" d + sh "$0" c ;; "t"*) - [ $(ps aux | grep wpa_supplicant | wc -l) -eq 2 ] && sh $0 d && exit - sh $0 c + [ "$(pgrep -c wpa_supplicant)" -eq 1 ] && sh "$0" d && exit + sh "$0" c ;; "l"*) iw dev wlp3s0 scan | \ grep 'SSID\|signal' | \ - grep -v '* SSID List' | \ + grep -v 'SSID List' | \ awk -F': ' '{print $2}' | \ sed 'N;s/\n/ /' | \ grep -v '\x00' ;; *) - printf "\ + echo " simple wrapper for connecting to a network ${0} toggle to toggle wifi connection ${0} restart to restart wifi diff --git a/sh/disp b/sh/disp index 9e20d57..026da93 100755 --- a/sh/disp +++ b/sh/disp @@ -1,12 +1,12 @@ #!/bin/sh exists() { - xrandr | grep ' connected' | grep "${1}" | wc -l + xrandr | grep ' connected' | grep -c "${1}" } bspc monitor -d 1 2 3 4 5 6 7 8 9 -if [ $(exists "HDMI-2") -eq 1 ] && [ $(exists "LVDS-1") -eq 1 ]; then +if [ "$(exists "HDMI-2")" -eq 1 ] && [ "$(exists "LVDS-1")" -eq 1 ]; then printf "two" xrandr --output HDMI-2 --right-of LVDS-1 --auto xrandr --output VGA-1 --off --auto diff --git a/sh/fire b/sh/fire index 60903bf..298f915 100755 --- a/sh/fire +++ b/sh/fire @@ -1,3 +1,3 @@ #!/bin/sh -HOME="/home/usr/.local/share/firefox" firefox $@ +HOME="/home/usr/.local/share/firefox" firefox "$@" diff --git a/sh/git-survey b/sh/git-survey index 2dac26c..8f6b862 100755 --- a/sh/git-survey +++ b/sh/git-survey @@ -1,11 +1,10 @@ #!/bin/sh -for i in $(ls); do - cd $i +for i in *; do + cd "$i" || continue exists=$( - git status |\ - grep 'Your branch is ahead of ' |\ - wc -l + git status | + grep -c 'Your branch is ahead of ' ) [ "$exists" -eq 0 ] || printf "> %s\n" "$i" diff --git a/sh/net b/sh/net index 70b74a5..e79c8f9 100755 --- a/sh/net +++ b/sh/net @@ -1,4 +1,4 @@ #!/bin/sh # designed to be called from sxhkd (x session) -[ "$(pgrep NetworkManager)" ] && st -e nmtui +pgrep NetworkManager && st -e nmtui diff --git a/sh/nws b/sh/nws index b0f415e..056d52c 100755 --- a/sh/nws +++ b/sh/nws @@ -3,8 +3,8 @@ [ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config" [ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws" [ -n "${NWS_ZONE}" ] || \ - [ -e ${NWS_CONFIG} ] && NWS_ZONE=$(cat ${NWS_CONFIG}) || \ - NWS_ZONE="KGYX" + [ -e "${NWS_CONFIG}" ] && NWS_ZONE=$(cat "${NWS_CONFIG}") || + NWS_ZONE="KGYX" [ -z "${NWS_GIF}" ] && NWS_GIF="mpv --loop" [ -z "${NWS_TORIFY}" ] && NWS_TORIFY="" @@ -28,9 +28,9 @@ Torify wrapper: export NWS_TORIFY= " } err () { - printf "err: %s\n" ${1} + printf "err: %s\n" "${1}" [ -z "${2}" ] && exit 1 - exit ${2} + exit "${2}" } kstrip () { printf %s "$1" | sed 's/^K\(.*\)/\1/' @@ -46,7 +46,7 @@ mosaic () { ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif" } setzone () { - printf "%s" "${1}" > ${NWS_CONFIG} + printf "%s" "${1}" > "${NWS_CONFIG}" } river () { textmessage "RVA" @@ -66,36 +66,39 @@ textmessage () { case $1 in "n"*) national - exit 0 ;; "l"*) localradar - exit 0 ;; "r"*) river - exit 0 ;; "w"*) weather - exit 0 ;; "m"*) - [ $# -eq 2 ] && mosaid $2 || \ + if [ "$#" -eq 2 ]; then + mosaid "$2" + else err "two args required" + fi ;; "s"*) - [ $# -eq 2 ] && setzone $2 || \ + if [ "$#" -eq 2 ]; then + setzone "$2" + else err "two args required" - exit 0 + fi ;; "t"*) - [ $# -eq 2 ] && textmessage $2 || \ + if [ "$#" -eq 2 ]; then + textmessage "$2" + else err "two args required" + fi ;; *) info - exit 0 ;; esac exit 0 diff --git a/sh/pash-dmenu b/sh/pash-dmenu index 2aa92ba..3929379 100755 --- a/sh/pash-dmenu +++ b/sh/pash-dmenu @@ -4,4 +4,4 @@ sel="$(pash l | tmenu)" [ "$?" -eq 1 ] && exit 0 # requires bspc rule -a st-gpg-menu state=floating -st -c st-gpg-menu -e pash-dmenu-backend $sel +st -c st-gpg-menu -e pash-dmenu-backend "$sel" diff --git a/sh/sfeed_yt_add b/sh/sfeed_yt_add index 43c8a95..4cd2937 100755 --- a/sh/sfeed_yt_add +++ b/sh/sfeed_yt_add @@ -5,15 +5,13 @@ printf "[info] this utility is used for adding youtube urls as rss feeds\n" -feed="$(curl ${1} -s | \ +feed="$(curl "$1" -s | \ grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \ awk -F'/' '{print "https://www.youtube.com/feeds/videos.xml?channel_id=" $NF}' | \ sed 1q)" [ -z "$feed" ] && printf "[err] error processing the feed. are you sure it's *www*.youtube.com and not youtube.com?\n" && exit 1 -tmp="$(mktemp)" - sfeedrc="$HOME/.config/sfeed/sfeedrc" ed "$sfeedrc" <&1 > /dev/null - kill $i + pkill -P "$i" >/dev/null 2>&1 + kill "$i" done # get all screens @@ -16,6 +18,6 @@ screens="$(xrandr | grep ' connected' | sed 's/ primary//g' | awk -F' ' '{print IFS=" " for i in $screens; do - screenstring=$(echo $i | awk -v a="$barwidth" -F'[ x+]' '{print $2 "x" a "+" $4 "+" $5}') + screenstring=$(echo "$i" | awk -v a="$barwidth" -F'[ x+]' '{print $2 "x" a "+" $4 "+" $5}') st -c statusbar -p -g "$screenstring" -e status & done diff --git a/sh/tmenu-backend b/sh/tmenu-backend index 28b755b..02289d2 100755 --- a/sh/tmenu-backend +++ b/sh/tmenu-backend @@ -1,6 +1,6 @@ #!/bin/sh -printf "%s" $1 +printf "%s" "$1" -fzy $2 < "$1" > "${1}a" -mv ${1}a ${1} +fzy "$2" < "$1" > "${1}a" +mv "${1}a" "${1}" diff --git a/sh/tmenu_run b/sh/tmenu_run index 1b57921..cc42dca 100755 --- a/sh/tmenu_run +++ b/sh/tmenu_run @@ -4,7 +4,7 @@ tmenu_path () { IFS=" :" for i in $PATH; do for j in "$i"/*; do - [ -f $j ] && [ -x $j ] && printf "%s\n" $j + [ -f "$j" ] && [ -x "$j" ] && printf "%s\n" "$j" done done } diff --git a/sh/vim-swap-handler b/sh/vim-swap-handler index bf39d6c..06082af 100755 --- a/sh/vim-swap-handler +++ b/sh/vim-swap-handler @@ -19,7 +19,7 @@ desk=$( ) [ "$desk" = "none" ] && exit 1 -desk=$(($desk + 1)) +desk=$((desk + 1)) bspc desktop -f "^${desk}" killall -10 simplestatus diff --git a/sh/vol b/sh/vol index 0cd2572..7bcd832 100755 --- a/sh/vol +++ b/sh/vol @@ -1,16 +1,16 @@ #!/bin/sh -pulse=$(ps aux | grep pulseaudio | wc -l) +pulse=$(pgrep -c pulseaudio) [ "$1" = "inc" ] && sign="+" [ "$1" = "dec" ] && sign="-" [ "$#" -eq 0 ] && exit 1 -if [ "$pulse" -eq 2 ]; then - for SINK in `pacmd list-sinks | grep 'index:' | cut -b12-` +if [ "$pulse" -eq 1 ]; then + for SINK in $(pacmd list-sinks | grep 'index:' | cut -b12-) do - pactl set-sink-volume $SINK "${sign}5%" + pactl set-sink-volume "$SINK" "${sign}5%" done else amixer -c 0 set Master "5%${sign}" diff --git a/sh/wallpaper b/sh/wallpaper index 83fe25d..2b519eb 100755 --- a/sh/wallpaper +++ b/sh/wallpaper @@ -1,12 +1,11 @@ #!/bin/sh WALLDIR="${HOME}/.local/share/wallpapers" -TEEFILE="${WALLDIR}/.hist" BASECMD="feh --no-fehbg --bg-fill" generate_wall () { GENWALL=$( \ - ls $WALLDIR | \ + ls "$WALLDIR" | \ grep "." | \ shuf -n 1 ) @@ -19,26 +18,15 @@ wall () { done } displays () { - displays=$(xrandr | grep ' connected' | wc -l) -} -check () { - which $1 &>/dev/null + displays=$(xrandr | grep -c ' connected') } cmd="" -check "feh" || exit 1 -if check "xrandr"; then - displays - for i in $(seq 1 $displays); do - wall ${tmp} - tmp=${GENWALL} - echo ${GENWALL} ${i} | tee $TEEFILE - cmd="${cmd} ${GENWALL}" - done - eval ${BASECMD} ${cmd} -else - generate_wall - eval ${BASECMD} ${GENWALL} -fi -unset GENWALL BASECMD tmp cmd displays i +displays +for i in $(seq 1 "$displays"); do + wall "${tmp}" + tmp="${GENWALL}" + cmd="${cmd} ${GENWALL}" +done +eval "${BASECMD}" "${cmd}" exit 0