commit 4e0efa213ee04af6142b2f1a192c5780adb0abff
parent 9aa9a0bd5e3934615a0b2e9d2d44b9dfbf51747f
Author: regexghost <dev@regexghost.com>
Date: Fri, 17 Jul 2026 19:21:51 +0100
more .kshrc trimming + dwm-bar.sh and music-mpd.sh (switching to mpd soon)
Diffstat:
3 files changed, 269 insertions(+), 16 deletions(-)
diff --git a/dotfiles/.kshrc b/dotfiles/.kshrc
@@ -147,27 +147,11 @@ do_pkill () {
alias pkill='do_pkill'
-storage () {
- root_line=$(df -h | grep ' /$' | tr -s " ")
- used=$(echo "$root_line" | cut -d " " -f 3)
- free=$(echo "$root_line" | cut -d " " -f 4)
- echo "Used: ${used}"
- echo "Free: ${free}"
-}
-
trash-empty () {
echo "Trash is $(trash-size)"
/usr/bin/trash-empty
}
-backuphistory () {
- wc -l ~/.history
- read yesOrNoBackup"?Backup? (y/N) "
- if [ "$yesOrNoBackup" = "y" ] || [ "$yesOrNoBackup" = "Y" ]; then
- cp ~/.history ~/Downloads/.history_backup
- fi
-}
-
# Only use this if the history in the current terminal is suddenly way shorter than it should be
restorehistory () {
history | sed 's/^[ ]*[0-9]*[ ]*//g' > /tmp/new_history
diff --git a/panel-scripts/dwm-bar.sh b/panel-scripts/dwm-bar.sh
@@ -0,0 +1,193 @@
+#!/bin/sh
+
+echo "$$" > ~/.cache/bar_pid
+
+. "$XDG_CONFIG_HOME/regexghost/current-theme.sh"
+
+COLOUR_RESET="\x01"
+sunset_colour="\x02"
+sunrise_colour="\x04"
+network_down_colour="\x06"
+cpu_colour="\x05"
+cpu_temp_colour="\x02"
+memory_colour="\x04"
+uptime_colour="\x03"
+muted_colour="\x02"
+volume_colour="\x03"
+music_stopped_colour="\x02"
+music_playing_colour="\x03"
+music_paused_colour="\x04"
+wifi_up_colour="\x03"
+wifi_down_colour="\x02"
+stream_live_colour="\x02"
+stream_not_live_colour="\x03"
+stream_error_colour="\x02"
+
+update_time () {
+ current_time="$(date +"%a %d %b - %H:%M")"
+}
+
+update_cpu () {
+ cpu="${cpu_colour}$(~/.local/share/regexghost/panel/cpu)%${COLOUR_RESET}"
+}
+
+update_network_down () {
+ network_down="${network_down_colour}"$(~/.local/share/regexghost/panel/network_down)"${COLOUR_RESET}"
+}
+
+update_vol () {
+ if [ $(cat ~/.cache/muted) = "yes" ]; then
+ vol="${muted_colour}Muted${COLOUR_RESET}"
+ else
+ vol="${volume_colour}$(cat ~/.cache/volume)%%${COLOUR_RESET}"
+ fi
+}
+
+update_wifi () {
+ con="$(nmcli -t -f NAME c show --active | grep -v "^lo$" | string-trunc 6 ".." | sed 's/ $//g')"
+ if [ "$con" = "" ]; then
+ wifi="${wifi_down_colour}N/A${COLOUR_RESET}"
+
+ else
+ wifi="${wifi_up_colour}${con}${COLOUR_RESET}"
+ fi
+}
+
+update_mem () {
+ memory="${memory_colour}"$(free -m | awk '/Mem:/ {print $3}')MiB"${COLOUR_RESET}"
+}
+
+update_cpu_temp () {
+ temp=$(($(cat /sys/class/thermal/thermal_zone2/temp)/1000))
+ cpu_temp="${cpu_temp_colour}""${temp}°C""${COLOUR_RESET}"
+}
+
+update_uptime () {
+ uptime="${uptime_colour}"$(~/.local/share/regexghost/panel/uptime)"${COLOUR_RESET}"
+}
+
+update_sunrise () {
+ sunrise="${sunrise_colour}"$(~/.local/share/regexghost/panel/sunrise.sh --sunrise --blank)"${COLOUR_RESET}"
+}
+
+update_sunset () {
+ sunset="${sunset_colour}"$(~/.local/share/regexghost/panel/sunrise.sh --sunset --blank)"${COLOUR_RESET}"
+}
+
+#update_weather () {
+# weather_days="$(~/.local/share/regexghost/panel/metoffice.sh)"
+# weather_today="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '1q;d')")"
+# weather_tomorrow="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '2q;d')")"
+# weather_2_days="$(~/.local/share/regexghost/panel/weather-formatter.sh --lemonbar "$(echo "$weather_days" | sed '3q;d')")"
+# weather="0${weather_today} 1${weather_tomorrow} 2${weather_2_days}"
+#}
+
+# This is done by index so I can change the streams checked by just altering the order in the config file
+stream_live () {
+ streamer_name="$(sed -n "${1}p" "$XDG_CONFIG_HOME/regexghost/streams.csv" | cut -d "," -f 1)"
+ first_char="$(echo "$streamer_name" | cut -c 1-1)"
+ live="$(stream-check -yn "$streamer_name")"
+ if [ "$live" = "y" ]; then
+ echo "${first_char} ${stream_live_colour}L ${COLOUR_RESET}"
+ elif [ "$live" = "w" ]; then
+ echo "${first_char} ${stream_not_live_colour}U ${COLOUR_RESET}"
+ elif [ "$live" = "n" ]; then
+ echo "${first_char} ${stream_not_live_colour}O ${COLOUR_RESET}"
+ else
+ echo "${first_char} ${stream_error_colour}E ${COLOUR_RESET}"
+ fi
+}
+
+update_streams () {
+ stream="$(stream_live 1) $(stream_live 2) $(stream_live 3)"
+}
+
+update_music () {
+ state="$(mpc status | grep "^\[")"
+ song="$(mpc current -f '%title% - %artist%' | string-trunc 16 ".." | sed 's/ $//g')"
+ if [ "$state" = "" ]; then
+ music="${music_stopped_colour}N/A${COLOUR_RESET}"
+ elif echo "$state" | grep -q "playing"; then
+ music="${music_playing_colour}${song}${COLOUR_RESET}"
+ elif echo "$state" | grep -q "paused"; then
+ music="${music_paused_colour}${song}${COLOUR_RESET}"
+ fi
+}
+
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+#
+
+display () {
+ printf " ${music} | ${stream}| ${sunset} | ${sunrise} | ${vol} | ${network_down} | ${wifi} | ${cpu} | ${uptime} | ${cpu_temp} | ${memory} | ${current_time} "
+}
+
+display
+
+update_vol
+update_wifi
+update_time
+update_sunrise
+update_sunset
+#update_weather
+update_streams
+update_music
+
+i=1
+
+trap "update_vol;display" "RTMIN"
+trap "update_music;display" "RTMIN+1"
+
+mpd () {
+ mpc idleloop player | while read -r _; do
+ kill -35 $(cat ~/.cache/bar_pid)
+ done &
+}
+
+mpd &
+
+while true; do
+ sleep 2 & wait && {
+ update_network_down
+ update_cpu
+ update_mem
+ update_uptime
+ update_cpu_temp
+ update_vol
+ [ $((i%3)) -eq 0 ] && update_time
+ [ $((i%3)) -eq 0 ] && update_wifi
+ [ $((i%3)) -eq 0 ] && update_music
+ [ $((i % 180)) -eq 0 ] && update_sunset
+ [ $((i % 300)) -eq 0 ] && update_sunrise
+ [ $((i % 600)) -eq 0 ] && update_streams
+# [ $((i % 360)) -eq 0 ] && update_weather
+ i=$((i+1))
+ [ $i -gt 900 ] && i=0
+ display
+ }
+done
diff --git a/panel-scripts/music-mpd.sh b/panel-scripts/music-mpd.sh
@@ -0,0 +1,76 @@
+#!/usr/bin/env sh
+
+# Music playing script (mpd/mpc)
+
+DMENU_SCRIPT="$XDG_DATA_HOME/regexghost/wm-scripts/dmenu-runner.sh"
+MUSIC_DIR="$HOME/Music"
+FAVOURITES_DIR="$MUSIC_DIR/Favourites"
+
+# Technically these first 4 are unnecessary, could just bind directly to the command
+# but I like it all being in one file
+if [ "$1" = "--toggle-pause" ]; then
+ mpc pause-if-playing || play
+ exit
+elif [ "$1" = "--quit" ]; then
+ mpc stop
+ mpc clear
+ exit
+elif [ "$1" = "--next" ]; then
+ mpc next
+ exit
+elif [ "$1" = "--previous" ]; then
+ mpc prev
+ exit
+elif [ "$1" = "--favourite" ]; then
+ song="$(mpc current -f '%file%')"
+ echo "$song" | grep -q "CurrentPlaylist/" && exit
+ favourite_path="$song"
+ favourite_dir="$(dirname "$favourite_path")"
+ mkdir -p "$FAVOURITES_DIR/${favourite_dir}"
+ ln -sf "${MUSIC_DIR}/${song}" "$FAVOURITES_DIR/${favourite_path}"
+ notify-send "Added to favourites"
+ exit
+elif [ "$1" = "--get-song" ]; then
+ song="$(mpc current -f '%title%')"
+ [ "$song" = "" ] && echo "None" && exit
+ echo "$song"
+ exit
+fi
+
+# Start mpd if not running, and set mode to shuffle
+if ! pgrep mpd 2> /dev/null > /dev/null; then
+ mpd
+ sleep 0.5
+fi
+
+# If mpd is currently playing music, just notify-send the song title
+if ! mpc status | grep -q "^\[playing\]"; then
+ song_name="$(mpc current -f '%artist% - %title%')"
+ notify-send -i emblem-music-symbolic "Currently Playing:" "$song_name"
+ exit
+fi
+
+if [ "$1" = "--choice" ]; then
+ # Ask for playlist
+ playlist="$(ls "$MUSIC_DIR" | sed 's/\([A-Z][a-z]\)/ \1/g' | sed 's/\([a-z]\)\([0-9]\)/\1 \2/g' | sed 's/^ //g' | "${DMENU_SCRIPT}" "Select Playlist:")"
+ [ "$?" != "0" ] && exit
+ playlist_path="$(echo "$playlist" | sed 's/ //g')"
+else
+ playlist_path="CurrentPlaylist"
+fi
+
+# Check for sub playlists
+if [ $(find "$playlist_path" -type d | wc -l) -ne 1 ]; then
+ playlist="$(ls "$playlist_path" | sed 's/\([A-Z][a-z]\)/ \1/g' | sed 's/\([a-z]\)\([0-9]\)/\1 \2/g' | sed 's/^ //g' | awk 'BEGIN {RS = ""} {print "All Songs\n"$0}' | "${DMENU_SCRIPT}" "Select Playlist:")"
+ [ "$?" != "0" ] && exit
+ # If all songs, don't change playlist path
+ if ! [ "$playlist" = "All Songs" ]; then
+ playlist_path="$playlist_path/$(echo "$playlist" | sed 's/ //g')"
+ fi
+fi
+
+mpc clear
+mpc add "$playlist_path"
+mpc repeat on
+mpc shuffle
+mpc play