add changes recommended/needed as indicated by shellcheck

This commit is contained in:
randomuser 2022-11-27 17:04:53 +00:00
parent 98d0a2fd68
commit 8594f34cb6
15 changed files with 63 additions and 72 deletions

View File

@ -1,36 +1,37 @@
#!/bin/sh #!/bin/sh
[ "$(ps -aux | grep -c NetworkManager)" -eq 2 ] && \ [ "$(pgrep -c NetworkManager)" -eq 1 ] &&
printf "NetworkManager is already running!" && \ printf "NetworkManager is already running!\n" &&
exit exit
case $1 in case $1 in
"c"*) "c"*)
wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B wpa_supplicant -iwlp3s0 -c/etc/wpa_supplicant/wpa_supplicant.conf -B
dhcpcd wlp3s0 dhcpcd wlp3s0
tor & disown # make tor and nohup shut up in a posix-compliant way
nohup tor >/dev/null 2>&1
;; ;;
"d"*) "d"*)
killall -15 wpa_supplicant dhcpcd tor killall -15 wpa_supplicant dhcpcd tor
;; ;;
"r"*) "r"*)
sh $0 d sh "$0" d
sh $0 c sh "$0" c
;; ;;
"t"*) "t"*)
[ $(ps aux | grep wpa_supplicant | wc -l) -eq 2 ] && sh $0 d && exit [ "$(pgrep -c wpa_supplicant)" -eq 1 ] && sh "$0" d && exit
sh $0 c sh "$0" c
;; ;;
"l"*) "l"*)
iw dev wlp3s0 scan | \ iw dev wlp3s0 scan | \
grep 'SSID\|signal' | \ grep 'SSID\|signal' | \
grep -v '* SSID List' | \ grep -v 'SSID List' | \
awk -F': ' '{print $2}' | \ awk -F': ' '{print $2}' | \
sed 'N;s/\n/ /' | \ sed 'N;s/\n/ /' | \
grep -v '\x00' grep -v '\x00'
;; ;;
*) *)
printf "\ echo "
simple wrapper for connecting to a network simple wrapper for connecting to a network
${0} toggle to toggle wifi connection ${0} toggle to toggle wifi connection
${0} restart to restart wifi ${0} restart to restart wifi

View File

@ -1,12 +1,12 @@
#!/bin/sh #!/bin/sh
exists() { 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 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" printf "two"
xrandr --output HDMI-2 --right-of LVDS-1 --auto xrandr --output HDMI-2 --right-of LVDS-1 --auto
xrandr --output VGA-1 --off --auto xrandr --output VGA-1 --off --auto

View File

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
HOME="/home/usr/.local/share/firefox" firefox $@ HOME="/home/usr/.local/share/firefox" firefox "$@"

View File

@ -1,11 +1,10 @@
#!/bin/sh #!/bin/sh
for i in $(ls); do for i in *; do
cd $i cd "$i" || continue
exists=$( exists=$(
git status |\ git status |
grep 'Your branch is ahead of ' |\ grep -c 'Your branch is ahead of '
wc -l
) )
[ "$exists" -eq 0 ] || printf "> %s\n" "$i" [ "$exists" -eq 0 ] || printf "> %s\n" "$i"

2
sh/net
View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
# designed to be called from sxhkd (x session) # designed to be called from sxhkd (x session)
[ "$(pgrep NetworkManager)" ] && st -e nmtui pgrep NetworkManager && st -e nmtui

29
sh/nws
View File

@ -3,7 +3,7 @@
[ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config" [ -z "${XDG_CONFIG_DIR}" ] && XDG_CONFIG_DIR="${HOME}/.config"
[ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws" [ -z "${NWS_CONFIG}" ] && NWS_CONFIG="${XDG_CONFIG_DIR}/nws"
[ -n "${NWS_ZONE}" ] || \ [ -n "${NWS_ZONE}" ] || \
[ -e ${NWS_CONFIG} ] && NWS_ZONE=$(cat ${NWS_CONFIG}) || \ [ -e "${NWS_CONFIG}" ] && NWS_ZONE=$(cat "${NWS_CONFIG}") ||
NWS_ZONE="KGYX" NWS_ZONE="KGYX"
[ -z "${NWS_GIF}" ] && NWS_GIF="mpv --loop" [ -z "${NWS_GIF}" ] && NWS_GIF="mpv --loop"
[ -z "${NWS_TORIFY}" ] && NWS_TORIFY="" [ -z "${NWS_TORIFY}" ] && NWS_TORIFY=""
@ -28,9 +28,9 @@ Torify wrapper: export NWS_TORIFY=<command>
" "
} }
err () { err () {
printf "err: %s\n" ${1} printf "err: %s\n" "${1}"
[ -z "${2}" ] && exit 1 [ -z "${2}" ] && exit 1
exit ${2} exit "${2}"
} }
kstrip () { kstrip () {
printf %s "$1" | sed 's/^K\(.*\)/\1/' printf %s "$1" | sed 's/^K\(.*\)/\1/'
@ -46,7 +46,7 @@ mosaic () {
${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif" ${NWS_GIF} "https://radar.weather.gov/ridge/lite/${1}_loop.gif"
} }
setzone () { setzone () {
printf "%s" "${1}" > ${NWS_CONFIG} printf "%s" "${1}" > "${NWS_CONFIG}"
} }
river () { river () {
textmessage "RVA" textmessage "RVA"
@ -66,36 +66,39 @@ textmessage () {
case $1 in case $1 in
"n"*) "n"*)
national national
exit 0
;; ;;
"l"*) "l"*)
localradar localradar
exit 0
;; ;;
"r"*) "r"*)
river river
exit 0
;; ;;
"w"*) "w"*)
weather weather
exit 0
;; ;;
"m"*) "m"*)
[ $# -eq 2 ] && mosaid $2 || \ if [ "$#" -eq 2 ]; then
mosaid "$2"
else
err "two args required" err "two args required"
fi
;; ;;
"s"*) "s"*)
[ $# -eq 2 ] && setzone $2 || \ if [ "$#" -eq 2 ]; then
setzone "$2"
else
err "two args required" err "two args required"
exit 0 fi
;; ;;
"t"*) "t"*)
[ $# -eq 2 ] && textmessage $2 || \ if [ "$#" -eq 2 ]; then
textmessage "$2"
else
err "two args required" err "two args required"
fi
;; ;;
*) *)
info info
exit 0
;; ;;
esac esac
exit 0 exit 0

View File

@ -4,4 +4,4 @@ sel="$(pash l | tmenu)"
[ "$?" -eq 1 ] && exit 0 [ "$?" -eq 1 ] && exit 0
# requires bspc rule -a st-gpg-menu state=floating # 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"

View File

@ -5,15 +5,13 @@
printf "[info] this utility is used for adding youtube urls as rss feeds\n" 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 | \ grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \
awk -F'/' '{print "https://www.youtube.com/feeds/videos.xml?channel_id=" $NF}' | \ awk -F'/' '{print "https://www.youtube.com/feeds/videos.xml?channel_id=" $NF}' | \
sed 1q)" 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 [ -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" sfeedrc="$HOME/.config/sfeed/sfeedrc"
ed "$sfeedrc" <<EOF ed "$sfeedrc" <<EOF

View File

@ -4,7 +4,7 @@ power_prefix="/sys/class/power_supply/"
[ -d "${power_prefix}sbs-20-000b" ] && bat="sbs-20-000b" [ -d "${power_prefix}sbs-20-000b" ] && bat="sbs-20-000b"
[ -d "${power_prefix}BAT0" ] && bat="BAT0" [ -d "${power_prefix}BAT0" ] && bat="BAT0"
[ "$(ps aux | grep pulseaudio | wc -l)" -eq 2 ] && ss="pulse" || ss="alsa" [ "$(pgrep -c pulseaudio)" -eq 1 ] && ss="pulse" || ss="alsa"
mod_bspwm () { mod_bspwm () {
used_desk=$(bspc query -D -d .occupied --names | tr '\n' ' ') used_desk=$(bspc query -D -d .occupied --names | tr '\n' ' ')
@ -67,7 +67,7 @@ echo_bar () {
printf "\033[2J\033[H%s" "$left" printf "\033[2J\033[H%s" "$left"
# print right side # print right side
printf "\033[1;%if%s" "$(($width - $rightwidth + 1))" "$right" printf "\033[1;%if%s" "$((width - rightwidth + 1))" "$right"
} }
register_sigs () { register_sigs () {
@ -94,5 +94,5 @@ while true; do
sleep 0.25 sleep 0.25
[ "$i" -eq $((29 * 4)) ] && update_all && i=0 [ "$i" -eq $((29 * 4)) ] && update_all && i=0
echo_bar echo_bar
i="$(($i + 1))" i="$((i + 1))"
done done

View File

@ -3,10 +3,12 @@
barwidth=20 barwidth=20
# remove all current statusbars # remove all current statusbars
# pgrep doesn't handle arguments for running commands
# shellcheck disable=2009
processes="$(ps aux | grep 'st -c' | grep 'status' | awk -F' ' '{print $2}')" processes="$(ps aux | grep 'st -c' | grep 'status' | awk -F' ' '{print $2}')"
for i in $processes; do for i in $processes; do
pkill -P "$i" 2>&1 > /dev/null pkill -P "$i" >/dev/null 2>&1
kill $i kill "$i"
done done
# get all screens # get all screens
@ -16,6 +18,6 @@ screens="$(xrandr | grep ' connected' | sed 's/ primary//g' | awk -F' ' '{print
IFS=" IFS="
" "
for i in $screens; do 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 & st -c statusbar -p -g "$screenstring" -e status &
done done

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
printf "%s" $1 printf "%s" "$1"
fzy $2 < "$1" > "${1}a" fzy "$2" < "$1" > "${1}a"
mv ${1}a ${1} mv "${1}a" "${1}"

View File

@ -4,7 +4,7 @@ tmenu_path () {
IFS=" :" IFS=" :"
for i in $PATH; do for i in $PATH; do
for j in "$i"/*; do for j in "$i"/*; do
[ -f $j ] && [ -x $j ] && printf "%s\n" $j [ -f "$j" ] && [ -x "$j" ] && printf "%s\n" "$j"
done done
done done
} }

View File

@ -19,7 +19,7 @@ desk=$(
) )
[ "$desk" = "none" ] && exit 1 [ "$desk" = "none" ] && exit 1
desk=$(($desk + 1)) desk=$((desk + 1))
bspc desktop -f "^${desk}" bspc desktop -f "^${desk}"
killall -10 simplestatus killall -10 simplestatus

8
sh/vol
View File

@ -1,16 +1,16 @@
#!/bin/sh #!/bin/sh
pulse=$(ps aux | grep pulseaudio | wc -l) pulse=$(pgrep -c pulseaudio)
[ "$1" = "inc" ] && sign="+" [ "$1" = "inc" ] && sign="+"
[ "$1" = "dec" ] && sign="-" [ "$1" = "dec" ] && sign="-"
[ "$#" -eq 0 ] && exit 1 [ "$#" -eq 0 ] && exit 1
if [ "$pulse" -eq 2 ]; then if [ "$pulse" -eq 1 ]; then
for SINK in `pacmd list-sinks | grep 'index:' | cut -b12-` for SINK in $(pacmd list-sinks | grep 'index:' | cut -b12-)
do do
pactl set-sink-volume $SINK "${sign}5%" pactl set-sink-volume "$SINK" "${sign}5%"
done done
else else
amixer -c 0 set Master "5%${sign}" amixer -c 0 set Master "5%${sign}"

View File

@ -1,12 +1,11 @@
#!/bin/sh #!/bin/sh
WALLDIR="${HOME}/.local/share/wallpapers" WALLDIR="${HOME}/.local/share/wallpapers"
TEEFILE="${WALLDIR}/.hist"
BASECMD="feh --no-fehbg --bg-fill" BASECMD="feh --no-fehbg --bg-fill"
generate_wall () { generate_wall () {
GENWALL=$( \ GENWALL=$( \
ls $WALLDIR | \ ls "$WALLDIR" | \
grep "." | \ grep "." | \
shuf -n 1 shuf -n 1
) )
@ -19,26 +18,15 @@ wall () {
done done
} }
displays () { displays () {
displays=$(xrandr | grep ' connected' | wc -l) displays=$(xrandr | grep -c ' connected')
}
check () {
which $1 &>/dev/null
} }
cmd="" cmd=""
check "feh" || exit 1
if check "xrandr"; then
displays displays
for i in $(seq 1 $displays); do for i in $(seq 1 "$displays"); do
wall ${tmp} wall "${tmp}"
tmp=${GENWALL} tmp="${GENWALL}"
echo ${GENWALL} ${i} | tee $TEEFILE
cmd="${cmd} ${GENWALL}" cmd="${cmd} ${GENWALL}"
done done
eval ${BASECMD} ${cmd} eval "${BASECMD}" "${cmd}"
else
generate_wall
eval ${BASECMD} ${GENWALL}
fi
unset GENWALL BASECMD tmp cmd displays i
exit 0 exit 0