From 46c1bfc4ea69fceab10cb7493617723183366d54 Mon Sep 17 00:00:00 2001 From: saloniamatteo Date: Fri, 15 Nov 2024 17:48:46 +0100 Subject: [PATCH] Update bar scripts --- scripts/.local/bin/battery | 43 +++++++++++++------------ scripts/.local/bin/brightness | 42 ++++++++++++++++++------- scripts/.local/bin/capslock | 8 ++--- scripts/.local/bin/chardetect | 8 ----- scripts/.local/bin/clock | 11 ++----- scripts/.local/bin/cpu | 4 +-- scripts/.local/bin/emoji | 18 ----------- scripts/.local/bin/fanspeed | 22 ++++++------- scripts/.local/bin/forecast | 39 ----------------------- scripts/.local/bin/internet | 25 ++++++++++----- scripts/.local/bin/kbselect | 16 ---------- scripts/.local/bin/memory | 2 +- scripts/.local/bin/samloader | 33 -------------------- scripts/.local/bin/volume | 59 ++++++++++++++++++++++++----------- 14 files changed, 129 insertions(+), 201 deletions(-) delete mode 100755 scripts/.local/bin/chardetect delete mode 100755 scripts/.local/bin/emoji delete mode 100755 scripts/.local/bin/forecast delete mode 100755 scripts/.local/bin/kbselect delete mode 100755 scripts/.local/bin/samloader diff --git a/scripts/.local/bin/battery b/scripts/.local/bin/battery index 326c101..293d9be 100755 --- a/scripts/.local/bin/battery +++ b/scripts/.local/bin/battery @@ -6,33 +6,32 @@ case $BLOCK_BUTTON in 3) notify-send "🔋 Battery module" "🔋: discharging 🛑: not charging -♻ : stagnant charge +♻: stagnant charge 🔌: charging ⚡: charged ❗: battery very low! -📛: no battery attached - Scroll to change adjust xbacklight." ;; 4) xbacklight -inc 10 ;; 5) xbacklight -dec 10 ;; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; + 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; esac -# acpi alternative -# acpi | sed "s/Battery [0-9]: //;s/[Dd]ischarging, /🔋/;s/[Nn]ot charging, /🛑/;s/[Cc]harging, /🔌/;s/[Uu]nknown, /♻/;s/[Ff]ull, /⚡/;s/ \(remaining\|until charged\)//"; exit - -# If there is no battery attached -! [ -d /sys/class/power_supply/BAT? ] && printf "📛" - -# Loop through all attached batteries. -for battery in /sys/class/power_supply/BAT? -do - # Get its remaining capacity and charge status. - capacity=$(cat "$battery"/capacity 2>/dev/null) || break - status=$(sed "s/[Dd]ischarging/🔋/;s/[Nn]ot charging/🛑/;s/[Cc]harging/🔌/;s/[Uu]nknown/♻/;s/[Ff]ull/⚡/" "$battery"/status) - - # If it is discharging and 25% or less, we will add a ❗ as a warning. - [ "$capacity" -le 25 ] && [ "$status" = "🔋" ] && warn="❗" - - printf "%s%s%s%s%% " "$status" "$warn" "$capacity" - unset warn -done | sed 's/ *$//' +# Loop through all attached batteries and format the info +for battery in /sys/class/power_supply/BAT?*; do + # If non-first battery, print a space separator. + [ -n "${capacity+x}" ] && printf " " + # Sets up the status and capacity + case "$(cat "$battery/status" 2>&1)" in + "Full") status="⚡" ;; + "Discharging") status="🔋 " ;; + "Charging") status="🔌" ;; + "Not charging") status="🛑 " ;; + "Unknown") status="♻️" ;; + *) exit 1 ;; + esac + capacity="$(cat "$battery/capacity" 2>&1)" + # Will make a warn variable if discharging and low + [ "$status" = "🔋" ] && [ "$capacity" -le 25 ] && warn="❗" + # Prints the info + printf "%s%s%d%%" "$status" "$warn" " $capacity"; unset warn +done && printf "\\n" diff --git a/scripts/.local/bin/brightness b/scripts/.local/bin/brightness index 1349da0..cfa8b65 100755 --- a/scripts/.local/bin/brightness +++ b/scripts/.local/bin/brightness @@ -1,17 +1,35 @@ #!/bin/sh -# display current brightness +# Display current brightness -# get first two digits of brightness value -brightnum=$(xbacklight -get) -[[ "$brightnum" = "" ]] && echo "🚱" exit 1 -brightness=$(printf "${brightnum%.*}") +# current brightness +curr_brightness=$(cat /sys/class/backlight/*/brightness) -if [[ "$brightness" -gt "70" ]]; then - echo "🌞$brightness" -elif [[ "$brightness" -le "10" ]]; then - echo "🌑$brightness" -elif [[ "$brightness" -lt "30" ]]; then - echo "🌦$brightness" +# max_brightness +max_brightness=$(cat /sys/class/backlight/*/max_brightness) + +# brightness percentage +brightness_per=$((100 * curr_brightness / max_brightness)) + +case $BLOCK_BUTTON in + 1) + ;; + 3) + notify-send "💡 Brightness module" "\- Shows current brightness level ☀️." + ;; + 6) + setsid -f "$TERMINAL" -e "$EDITOR" "$0" + ;; +esac + +# Assign emoji based on brightness +if [[ $brightness_per -ge 70 ]]; then + bright_icon="🌞" +elif [[ $brightness_per -ge 40 && $brightness_per -lt 70 ]]; then + bright_icon="🌤️" +elif [[ $brightness_per -ge 15 && $brightness_per -lt 40 ]]; then + bright_icon="⛅" else - echo "⛅$brightness" + bright_icon="🌙" fi + +echo "${bright_icon} ${brightness_per}%" diff --git a/scripts/.local/bin/capslock b/scripts/.local/bin/capslock index 7348021..584be87 100755 --- a/scripts/.local/bin/capslock +++ b/scripts/.local/bin/capslock @@ -1,14 +1,14 @@ #!/bin/sh -# show if caps lock is on or off +# Show caps lock status -# caps lock status +# Get caps lock status capslock=$(xset q | grep "Caps Lock:" | awk '{print $4}') case $BLOCK_BUTTON in - 1) + 1) pkill -RTMIN+26 "${STATUSBAR:-dwmblocks}";; 3) notify-send "Caps Lock indicator" "Caps Lock is currently $capslock" ;; 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -printf "🔒$capslock" +printf "🔒 $capslock" diff --git a/scripts/.local/bin/chardetect b/scripts/.local/bin/chardetect deleted file mode 100755 index 099ef2c..0000000 --- a/scripts/.local/bin/chardetect +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/python3.9 -# -*- coding: utf-8 -*- -import re -import sys -from chardet.cli.chardetect import main -if __name__ == '__main__': - sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) - sys.exit(main()) diff --git a/scripts/.local/bin/clock b/scripts/.local/bin/clock index 896756e..99045e7 100755 --- a/scripts/.local/bin/clock +++ b/scripts/.local/bin/clock @@ -19,18 +19,11 @@ case "$clock" in esac case $BLOCK_BUTTON in - 1) - notify-send "Current hour" "$(date '+%R:%S')" - notify-send "Today's date" "$(date '+%A, %d %B %Y')" - notify-send "Yesterday's date" "$(date '+%A %d %B %y' -d 'yesterday')" - notify-send "Tomorrow's date" "$(date '+%A %d %B %y' -d 'tomorrow')" - notify-send "This Month" "$(cal --color=never -mS)" - ;; + 1) notify-send "This Month" "$(cal | sed "s/\<$(date +'%e'|tr -d ' ')\>/&<\/span><\/b>/")" && notify-send "Appointments" "$(calcurse -d3)" ;; 2) setsid -f "$TERMINAL" -e calcurse ;; 3) notify-send "📅 Time/date module" "\- Left click to show upcoming appointments for the next three days via \`calcurse -d3\` and show the month via \`cal\` - Middle click opens calcurse if installed" ;; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; + 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; esac -#echo " $(date '+%a %d %b %Y') $icon $(date '+%R')" echo "📅 $(date '+%a %d/%m/%Y') $icon $(date '+%R')" diff --git a/scripts/.local/bin/cpu b/scripts/.local/bin/cpu index 46f31f7..26bb41a 100755 --- a/scripts/.local/bin/cpu +++ b/scripts/.local/bin/cpu @@ -6,7 +6,7 @@ case $BLOCK_BUTTON in 3) notify-send "🖥 CPU module " "\- Shows CPU temperature. - Click to show intensive processes. - Middle click to open htop." ;; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; + 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; esac -printf "🌡$(sensors | grep "Core 0" | awk '{print $3}' | tr -d "+")" +sensors | awk '/Core 0/ {print "🌡 " $3}' | tr -d '+' diff --git a/scripts/.local/bin/emoji b/scripts/.local/bin/emoji deleted file mode 100755 index 3d25bf3..0000000 --- a/scripts/.local/bin/emoji +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh -# The famous "get a menu of emojis to copy" script. - -# Get user selection via dmenu from emoji file. -chosen=$(cut -d ';' -f1 ~/.local/share/emoji | dmenu -i -l 30 | sed "s/ .*//") - -# Exit if none chosen. -[ -z "$chosen" ] && exit - -# If you run this command with an argument, it will automatically insert the -# character. Otherwise, show a message that the emoji has been copied. -if [ -n "$1" ]; then - xdotool type "$chosen" -else - printf "$chosen" | xclip -selection clipboard - notify-send "'$chosen' copied to clipboard." & -fi - diff --git a/scripts/.local/bin/fanspeed b/scripts/.local/bin/fanspeed index 3f1a771..97c2a29 100755 --- a/scripts/.local/bin/fanspeed +++ b/scripts/.local/bin/fanspeed @@ -1,15 +1,15 @@ #!/bin/bash -# get fan speed +# Get ThinkPad fan speed -speed=$(cat /proc/acpi/ibm/fan | grep level | head -n 1 | awk '{print $2}') +# Get fan speed +speed=$(cat /proc/acpi/ibm/fan | awk '/level:/ {print $2}') -printf "💨" +icon="💨" -if [ "$speed" = "auto" ]; then - printf " a" -else if [ "$speed" = "disengaged" ]; then - printf " max" -else - printf " $speed" -fi -fi +case $speed in + "auto") tspeed="auto" ;; + "disengaged") tspeed="max" ;; + *) tspeed="$speed" ;; +esac + +echo "$icon $tspeed" diff --git a/scripts/.local/bin/forecast b/scripts/.local/bin/forecast deleted file mode 100755 index db90d7a..0000000 --- a/scripts/.local/bin/forecast +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -# Displays todays precipication chance (☔) and daily low (🥶) and high (🌞). -# Usually intended for the statusbar. - -# Set forecast location -LOCATION="Modica" - -# If we have internet, get a weather report from wttr.in and store it locally. -# You could set up a shell alias to view the full file in a pager in the -# terminal if desired. This function will only be run once a day when needed. -weatherreport="${XDG_DATA_HOME:-$HOME/.cache}/weatherreport" -getforecast() { curl -sf "wttr.in/$LOCATION" > "$weatherreport" || exit 1 ;} - -# Some very particular and terse stream manipulation. We get the maximum -# precipitation chance and the daily high and low from the downloaded file and -# display them with coresponding emojis. -showweather() { - printf "%s" "$(sed '16q;d' "$weatherreport" | - grep -wo "[0-9]*%" | sort -rn | sed "s/^/☔/g;1q" | tr -d '\n')" -sed '13q;d' "$weatherreport" | grep -o "m\\([-+]\\)*[0-9]\\+" | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " 🥶" $1 "°","🌞" $2 "°"}' ;} - -case $BLOCK_BUTTON in - 1) setsid -f "$TERMINAL" -e less -Srf "$weatherreport" ;; - 2) getforecast && showweather ;; - 3) notify-send "🌈 Weather module" "\- Left click for full forecast. -- Middle click to update forecast. -☔: Chance of rain/snow -🥶: Daily low -🌞: Daily high" ;; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; -esac - -# The test if our forcecast is updated to the day. If it isn't download a new -# weather report from wttr.in with the above function. -[ "$(stat -c %y "$weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || - getforecast - -showweather diff --git a/scripts/.local/bin/internet b/scripts/.local/bin/internet index a541c62..75446db 100755 --- a/scripts/.local/bin/internet +++ b/scripts/.local/bin/internet @@ -1,5 +1,4 @@ #!/bin/sh - # Show wifi 📶 and percent strength or 📡 if none. # Show 🌐 if connected to ethernet or ❎ if none. # Show 🔒 if a vpn connection is active @@ -7,19 +6,29 @@ case $BLOCK_BUTTON in 1) "$TERMINAL" -e nmtui; pkill -RTMIN+4 dwmblocks ;; 3) notify-send "🌐 Internet module" "\- Click to connect +❌: wifi disabled 📡: no wifi connection 📶: wifi connection with quality ❎: no ethernet 🌐: ethernet working 🔒: vpn is active " ;; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; + 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; esac -case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in - down) wifiicon="📡 " ;; - # up) wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" wifiname=$(iw dev wlp3s0 info | grep ssid | awk '{print $2}');; - up) wifiicon="$(awk '/^\s*w/ { print "📶 " }' /proc/net/wireless)" wifiname=$(iw dev wlp3s0 info | grep ssid | awk '{print $2}');; -esac +# Wifi +if [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'up' ] ; then + # Chanhe + wifiname="📶 $(iw dev | awk '/ssid/ {print $2}')" + wifiicon="$wifiname $(awk '/^\s*w/ { print int($3 * 100 / 70) "% " }' /proc/net/wireless)" +elif [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'down' ] ; then + [ "$(cat /sys/class/net/w*/flags 2>/dev/null)" = '0x1003' ] && wifiicon="📡 " || wifiicon="❌ " +fi + +# Ethernet +[ "$(cat /sys/class/net/e*/operstate 2>/dev/null)" = 'up' ] && ethericon="🌐 " || ethericon="❎ " + +# TUN +[ -n "$(cat /sys/class/net/tun*/operstate 2>/dev/null)" ] && tunicon=" 🔒" -printf "%s%s%s\n" "$wifiicon" "$wifiname " "$(sed "s/down/❎/;s/up/🌐/" /sys/class/net/e*/operstate 2>/dev/null)" "$(sed "s/.*/🔒/" /sys/class/net/tun*/operstate 2>/dev/null)" +printf "%s%s%s\n" "$wifiicon" "$ethericon" "$tunicon" diff --git a/scripts/.local/bin/kbselect b/scripts/.local/bin/kbselect deleted file mode 100755 index 2cbf38c..0000000 --- a/scripts/.local/bin/kbselect +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -# works on any init system -# requirements: dmenu, xorg-setxkbmap -kb="$(setxkbmap -query | grep -oP 'layout:\s*\K\w+')" || exit 1 - -case $BLOCK_BUTTON in - 1) kb_choice="$(awk '/! layout/{flag=1; next} /! variant/{flag=0} flag {print $2, "- " $1}' /usr/share/X11/xkb/rules/base.lst | dmenu -l 15)" - kb="$(echo "$kb_choice" | awk '{print $3}')" - setxkbmap "$kb" - pkill -RTMIN+30 "${STATUSBAR:-dwmblocks}";; - 3) notify-send "⌨ Keyboard/language module" "$(printf "%s" "\- Current layout: $(setxkbmap -query | grep -oP 'layout:\s*\K\w+')") -- Left click to change keyboard.";; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; -esac - -printf "$kb" diff --git a/scripts/.local/bin/memory b/scripts/.local/bin/memory index b1ce4d1..b684683 100755 --- a/scripts/.local/bin/memory +++ b/scripts/.local/bin/memory @@ -9,4 +9,4 @@ case $BLOCK_BUTTON in 6) "$TERMINAL" -e "$EDITOR" "$0" ;; esac -free --mega | sed -n '2{p;q}' | awk '{printf ("🖥%2.2fGB/%2.2fGB\n", ( $3 / 1000), ($2 / 1000))}' +free --mega | sed -n '2{p;q}' | awk '{printf ("🖥 %2.2fGB/%2.2fGB\n", ( $3 / 1000), ($2 / 1000))}' diff --git a/scripts/.local/bin/samloader b/scripts/.local/bin/samloader deleted file mode 100755 index 2ab1c48..0000000 --- a/scripts/.local/bin/samloader +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/python3.9 -# EASY-INSTALL-ENTRY-SCRIPT: 'samloader==0.3','console_scripts','samloader' -import re -import sys - -# for compatibility with easy_install; see #2198 -__requires__ = 'samloader==0.3' - -try: - from importlib.metadata import distribution -except ImportError: - try: - from importlib_metadata import distribution - except ImportError: - from pkg_resources import load_entry_point - - -def importlib_load_entry_point(spec, group, name): - dist_name, _, _ = spec.partition('==') - matches = ( - entry_point - for entry_point in distribution(dist_name).entry_points - if entry_point.group == group and entry_point.name == name - ) - return next(matches).load() - - -globals().setdefault('load_entry_point', importlib_load_entry_point) - - -if __name__ == '__main__': - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) - sys.exit(load_entry_point('samloader==0.3', 'console_scripts', 'samloader')()) diff --git a/scripts/.local/bin/volume b/scripts/.local/bin/volume index d7a8f5c..61966fb 100755 --- a/scripts/.local/bin/volume +++ b/scripts/.local/bin/volume @@ -1,32 +1,55 @@ #!/bin/sh - -# Prints the current volume or 🔇 if muted. +# Prints the current volume case $BLOCK_BUTTON in - 1) setsid -f "$TERMINAL" -e pulsemixer ;; - 2) pulsemixer --id sink-0 --toggle-mute ;; - 4) pulsemixer --id sink-0 --change-volume +5 ;; - 5) pulsemixer --id sink-0 --chang-volume -5 ;; + 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" ;; + 2) wpctl set-mute @DEFAULT_SINK@ toggle ;; + 4) wpctl set-volume @DEFAULT_SINK@ 1%+ ;; + 5) wpctl set-volume @DEFAULT_SINK@ 1%- ;; 3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted. - Middle click to mute. - Scroll to change." ;; - 6) "$TERMINAL" -e "$EDITOR" "$0" ;; + 6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; esac -micstat=$(amixer sget Capture | tail -n 1 | awk '{print $6}' | tr -d "[]") -[[ $micstat = "" ]] && micstat="off" +# Get speaker & mic volumes +spkvol="$(wpctl get-volume @DEFAULT_SINK@)" +micvol="$(wpctl get-volume @DEFAULT_SOURCE@)" + +# Omit the . without calling and external program. +split() { + IFS=$2 + set -- $1 + printf '%s' "$@" +} -[ $(pulsemixer --id source-1 --get-mute) = true ] && echo "🔇 🎤$micstat" && exit +# Check speaker volume +if [ "$spkvol" != "${spkvol%\[MUTED\]}" ]; then + spkicon="🔇" + spkvol="off" +else + spkvol="${spkvol#Volume: }" + spkvol="$(printf "%.0f" "$(split "$spkvol" ".")")" -vol="$(pulsemixer --id sink-0 --get-volume | awk '{print $1}')" -[[ "$vol" = 0 || "$vol" = "" ]] && echo "🔇 🎤$micstat" && exit + case 1 in + $((spkvol >= 70)) ) spkicon="🔊" ;; + $((spkvol >= 30)) ) spkicon="🔉" ;; + $((spkvol >= 1)) ) spkicon="🔈" ;; + * ) spkicon="🔇" ;; + esac + + spkvol="$spkvol%" +fi -if [ "$vol" -gt "70" ]; then - icon="🔊" -elif [ "$vol" -lt "30" ]; then - icon="🔈" +# Check mic volume +micicon="🎤" +if [ "$micvol" != "${micvol%\[MUTED\]}" ]; then + micvol="off" else - icon="🔉" + micvol="${micvol#Volume: }" + micvol="$(printf "%.0f" "$(split "$micvol" ".")")" + micvol="$micvol%" fi -echo "$icon$vol% 🎤$micstat" +# Print volumes +echo "$spkicon $spkvol $micicon $micvol"