handle err

This commit is contained in:
tavo 2024-12-28 14:54:46 -06:00
parent 52a7798bbe
commit 9d271de53e
5 changed files with 35 additions and 2 deletions

View file

@ -3,8 +3,19 @@
# 'https://stackoverflow.com/questions/9229333/how-to-get-overall-cpu-usage-e-g-57-on-linux'
# Yeti Oct 21, 2017 at 9:21
cat "$XDG_CACHE_HOME"/cpustat
if [ -n "$XDG_CACHE_HOME" ] ; then
cache_file="$XDG_CACHE_HOME"/cpustat
elif [ -n "$HOME" ] ; then
mkdir -p "$HOME/.local/cache"
cache_file="$HOME/.local/cache"/cpustat
else
exit 1
fi
if [ -f "$cache_file" ] ; then
cat "$cache_file"
fi
load=$({ head -n1 /proc/stat;sleep 0.3;head -n1 /proc/stat; } | awk '/^cpu /{u=$2-u;s=$4-s;i=$5-i;w=$6-w}END{print int(0.5+100*(u+s+w)/(u+s+i+w))}')
echo "$load%" > "$XDG_CACHE_HOME"/cpustat
echo "$load%" > "$cache_file"

View file

@ -3,5 +3,10 @@
layout="$(setxkbmap -query | awk '/layout/{ print $2 }' | sed 's/latam/la/')"
if [ "$?" != 0 ] ; then
echo "Failed to get layout"
exit 1
fi
echo "$layout"
# notify-send -u low --replace-id=12 "󰌌 Layout" "$layout"

View file

@ -4,6 +4,11 @@
info=$(amixer get Capture | grep -m 1 '[0-9]*%')
if [ "$?" != 0 ] ; then
echo "Failed to get Master volume"
exit 1
fi
if [ -z "${info##*\[off\]}" ] ; then
echo "󰍭 ──────────"
exit 0

View file

@ -22,11 +22,18 @@ int() { # Type of interface & status
# If down interfaces, exit with icon
grep -xq 'down' /sys/class/net/w*/operstate 2>/dev/null && echo "󰤮" && return 0
grep -xq 'down' /sys/class/net/e*/operstate 2>/dev/null && echo "󰲛" && return 0
return 1
}
# Run 'int'
icon=$(int)
if [ "$?" != 0 ] ; then
echo "Failed to get interface type"
exit 1
fi
# Check if a VPN is enabled
vpn="$( \
sed "s/.*//" /sys/class/net/tun*/operstate 2>/dev/null

View file

@ -4,6 +4,11 @@
info=$(amixer get Master | grep -m 1 '[0-9]*%')
if [ "$?" != 0 ] ; then
echo "Failed to get Master volume"
exit 1
fi
if [ -z "${info##*\[off\]}" ] ; then
echo "󰖁 ──────────"
exit 0