summaryrefslogtreecommitdiffstats
path: root/.local/bin
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/displayselect6
-rwxr-xr-x.local/bin/opout7
-rwxr-xr-x.local/bin/statusbar/sb-forecast22
-rwxr-xr-x.local/bin/statusbar/sb-iplocate21
-rwxr-xr-x.local/bin/statusbar/sb-moonphase23
-rwxr-xr-x.local/bin/statusbar/sb-price42
-rwxr-xr-x.local/bin/sysact13
7 files changed, 101 insertions, 33 deletions
diff --git a/.local/bin/displayselect b/.local/bin/displayselect
index 51dd468..3830bef 100755
--- a/.local/bin/displayselect
+++ b/.local/bin/displayselect
@@ -34,7 +34,7 @@ twoscreen() { # If multi-monitor is selected and there are two screens.
primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
secondary=$(echo "$screens" | grep -v ^"$primary"$)
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
- xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
+ xrandr --output "$primary" --primary --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
fi
}
@@ -43,7 +43,7 @@ morescreen() { # If multi-monitor is selected and there are more than two screen
secondary=$(echo "$screens" | grep -v ^"$primary"$ | dmenu -i -p "Select secondary display:")
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
tertiary=$(echo "$screens" | grep -v ^"$primary"$ | grep -v ^"$secondary"$ | dmenu -i -p "Select third display:")
- xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto
+ xrandr --output "$primary" --primary --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto
}
multimon() { # Multi-monitor handler.
@@ -53,7 +53,7 @@ multimon() { # Multi-monitor handler.
esac ;}
onescreen() { # If only one output available or chosen.
- xrandr --output "$1" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
+ xrandr --output "$1" --primary --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "\b$1" | awk '{print "--output", $1, "--off"}' | paste -sd ' ' -)
}
postrun() { # Stuff to run to clean up.
diff --git a/.local/bin/opout b/.local/bin/opout
index d2b447a..268c70d 100755
--- a/.local/bin/opout
+++ b/.local/bin/opout
@@ -7,7 +7,12 @@
basename="${1%.*}"
case "${*}" in
- *.tex|*.sil|*.m[dse]|*.[rR]md|*.mom|*.[0-9]) target="$(getcomproot "$1" || echo "$1")" ; setsid -f xdg-open "${target%.*}".pdf >/dev/null 2>&1 ;;
+ *.tex|*.sil|*.m[dse]|*.[rR]md|*.mom|*.[0-9])
+ target="$(getcomproot "$1" || echo "$1")"
+ target="${target##*/}"
+ target="$(find . -name "${target%.*}".pdf | head -n 1)"
+ setsid -f xdg-open "$target" >/dev/null 2>&1
+ ;;
*.html) setsid -f "$BROWSER" "$basename".html >/dev/null 2>&1 ;;
*.sent) setsid -f sent "$1" >/dev/null 2>&1 ;;
esac
diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast
index 5225601..645e7a2 100755
--- a/.local/bin/statusbar/sb-forecast
+++ b/.local/bin/statusbar/sb-forecast
@@ -7,11 +7,13 @@ url="${WTTRURL:-wttr.in}"
weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport"
# Get a weather report from 'wttr.in' and save it locally.
-getforecast() { timeout --signal=1 2s curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; }
+getforecast() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
+ curl -sf "$url/$LOCATION" --output "$weatherreport" && touch "$weatherreport"
+}
# Forecast should be updated only once a day.
checkforecast() {
- [ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null |
+ [ "$(stat -c %y "$weatherreport" 2>/dev/null |
cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
}
@@ -34,6 +36,7 @@ readfile() { weatherdata="$(cat "$weatherreport")" ;}
showweather() {
readfile
+ # shellcheck disable=SC2046,SC2183
printf "☔%s 🥶%s° 🌞%s°\n" "$(getprecipchance)" $(getdailyhighlow)
}
@@ -48,6 +51,15 @@ case $BLOCK_BUTTON in
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
-checkforecast || getforecast
-
-showweather
+# shellcheck disable=SC2015
+checkforecast && showweather ||
+ ( flock -n 9 &&
+ ( tries=0; while [ $tries -ne 100 ]; do
+ getforecast && break ||
+ { tries=$((tries+1)); sleep .1; }
+ done
+ ! checkforecast &&
+ until getforecast; do sleep 60; done
+ pkill -RTMIN+"${1:-5}" "${STATUSBAR:-dwmblocks}"
+ ) &
+ echo ) 9>"${XDG_RUNTIME_DIR}/sb-forecast.lock"
diff --git a/.local/bin/statusbar/sb-iplocate b/.local/bin/statusbar/sb-iplocate
index a9043e3..a1606e1 100755
--- a/.local/bin/statusbar/sb-iplocate
+++ b/.local/bin/statusbar/sb-iplocate
@@ -5,10 +5,25 @@
#
# https://www.maketecheasier.com/ip-address-geolocation-lookups-linux/
-set -e
+ifinstalled "geoip" || exit 1
-ifinstalled "geoip"
-addr="$(geoiplookup "$(curl -sfm 1 ifconfig.me 2>/dev/null)")"
+getip() {
+ { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
+ curl -sf api.ipify.org --output "$ipfile"
+}
+
+ipfile="$XDG_RUNTIME_DIR/iplocate"
+addr=$(cat "$ipfile" 2>/dev/null) && addr=$(geoiplookup "$addr" 2>/dev/null) && rm "$ipfile" ||
+ ( flock -n 9 &&
+ ( tries=0; while [ $tries -ne 100 ]; do
+ getip && break ||
+ { tries=$((tries+1)); sleep .1; }
+ done
+ ! [ -f "$ipfile" ] &&
+ until getip; do sleep 60; done &&
+ pkill -RTMIN+"${1:-27}" "${STATUSBAR:-dwmblocks}"
+ ) &
+ echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-iplocate.lock"
name="${addr##*, }"
flag="$(grep "flag: $name" "${XDG_DATA_HOME:-$HOME/.local/share}/larbs/emoji")"
flag="${flag%% *}"
diff --git a/.local/bin/statusbar/sb-moonphase b/.local/bin/statusbar/sb-moonphase
index d496ae2..145c1b7 100755
--- a/.local/bin/statusbar/sb-moonphase
+++ b/.local/bin/statusbar/sb-moonphase
@@ -4,8 +4,27 @@
moonfile="${XDG_DATA_HOME:-$HOME/.local/share}/moonphase"
-[ -s "$moonfile" ] && [ "$(stat -c %y "$moonfile" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] ||
- { curl -sf "wttr.in/?format=%m" > "$moonfile" || exit 1 ;}
+checkmoon() {
+ [ "$(stat -c %y "$moonfile" 2>/dev/null |
+ cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
+}
+
+getmoon() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
+ curl -sf "wttr.in/?format=%m" --output "$moonfile" && touch "$moonfile"
+}
+
+checkmoon ||
+ ( flock -n 9 &&
+ ( tries=0; while [ $tries -ne 100 ]; do
+ # shellcheck disable=SC2015
+ getmoon && break ||
+ { tries=$((tries+1)); sleep .1; }
+ done
+ ! checkmoon &&
+ until getmoon; do sleep 60; done
+ pkill -RTMIN+"${1:-17}" "${STATUSBAR:-dwmblocks}"
+ ) &
+ echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-moonphase.lock"
icon="$(cat "$moonfile")"
diff --git a/.local/bin/statusbar/sb-price b/.local/bin/statusbar/sb-price
index 6a79f8a..68f5146 100755
--- a/.local/bin/statusbar/sb-price
+++ b/.local/bin/statusbar/sb-price
@@ -24,22 +24,27 @@ interval="@14d" # History contained in chart preceded by '@' (7d = 7 days)
dir="${XDG_CACHE_HOME:-$HOME/.cache}/crypto-prices"
pricefile="$dir/$target-$denom"
chartfile="$dir/$target-$denom-chart"
-filestat="$(stat -c %x "$pricefile" 2>/dev/null)"
[ -d "$dir" ] || mkdir -p "$dir"
-updateprice() { curl -sf \
- --fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \
- --output "$pricefile" --output "$chartfile" ||
- rm -f "$pricefile" "$chartfile" ;}
+checkprice() {
+ [ "$(stat -c %y "$pricefile" 2>/dev/null |
+ cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ]
+}
-[ "${filestat%% *}" != "$(date '+%Y-%m-%d')" ] &&
- updateme="1"
+updateprice() { { grep -q -m1 '^up$' /sys/class/net/w*/operstate || grep -q -m1 '^up$' /sys/class/net/e*/operstate; } &&
+ curl -sf \
+ --fail-early "${denom}.${url}/1${target}" "${denom}.${url}/${target}${interval}" \
+ --output "$pricefile" --output "$chartfile" &&
+ touch "$pricefile" "$chartfile"
+}
+
+checkprice || updateme="1"
case $BLOCK_BUTTON in
1) setsid "$TERMINAL" -e less -Srf "$chartfile" ;;
2) notify-send -u low "$icon Updating..." "Updating $name price..." ; updateme="1" ; showupdate="1" ;;
- 3) uptime="$(date -d "$filestat" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
+ 3) uptime="$(date -d "$(stat -c %x "$pricefile" 2>/dev/null)" '+%D at %T' | sed "s|$(date '+%D')|Today|")"
notify-send "$icon $name module" "\- <b>Exact price: \$$(cat "$pricefile")</b>
- Left click for chart of changes.
- Middle click to update.
@@ -50,9 +55,22 @@ case $BLOCK_BUTTON in
esac
[ -n "$updateme" ] &&
- updateprice "$target" &&
- [ -n "$showupdate" ] &&
- notify-send "$icon Update complete." "$name price is now
-\$$(cat "$pricefile")"
+ if [ -n "$showupdate" ]; then
+ updateprice && notify-send "$icon Update complete." "$name price is now \$$(cat "$pricefile")"
+ else
+ # shellcheck disable=SC2015
+ [ -n "$4" ] &&
+ ( flock -n 9 &&
+ ( tries=0; while [ $tries -ne 100 ]; do
+ updateprice && break ||
+ { tries=$((tries+1)); sleep .1; }
+ done
+ ! checkprice &&
+ until updateprice; do sleep 60; done
+ pkill -RTMIN+"$4" "${STATUSBAR:-dwmblocks}"
+ ) &
+ echo; exit ) 9>"${XDG_RUNTIME_DIR}/sb-price.lock" ||
+ updateprice
+ fi
[ -f "$pricefile" ] && printf "%s%s%0.2f" "$icon" "$symb" "$(cat "$pricefile")"
diff --git a/.local/bin/sysact b/.local/bin/sysact
index 85488e5..038170b 100755
--- a/.local/bin/sysact
+++ b/.local/bin/sysact
@@ -14,13 +14,12 @@ wmpid(){ # This function is needed if there are multiple instances of the window
}
lock(){
- mpc pause
- pauseallmpv
- wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
- kill -44 $(pidof dwmblocks)
- slock
- wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
- kill -44 $(pidof dwmblocks)
+ was_muted="$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep -o 'MUTED' && echo 1 || echo 0)"
+ mpc pause & pauseallmpv &
+ wpctl set-mute @DEFAULT_AUDIO_SINK@ 1 &
+ slock
+ [ "$was_muted" -eq 0 ] && wpctl set-mute @DEFAULT_AUDIO_SINK@ 0
+ pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}"
}
case "$(printf "🔒 lock\n🚪 leave $WM\n♻️ renew $WM\n🐻 hibernate\n🔃 reboot\n🖥️shutdown\n💤 sleep\n📺 display off" | dmenu -i -p 'Action: ')" in