speedwm-personal/scripts/speedwm-stellar
2022-10-24 18:10:14 +02:00

440 lines
13 KiB
Bash
Executable file

#!/bin/sh
# Status bar for speedwm
# Written by speedie.gq in POSIX sh for https://speedie.gq/speedwm
# Licensed under the GNU GPLv3 free software license.
#
# NOTE: Anything in the DISPLAY function will be printed to your status bar.
# This means stdout will be printed regardless.
# You can output to /dev/null to silence most commands.
#
# Once you're done editing, run 'make clean install'.
#
# CONFIG
# This is the configuration for the status bar
#
# I highly recommend editing ~/.config/speedwm-de/status/config instead though
# All settings can be changed there. Otherwise, carefully edit the file and recompile speedwm!
if [ ! -e "$HOME/.config/speedwm-de/status/config" ]; then
cat <<EOF > ~/.config/speedwm-de/status/config
# status configuration
# General settings
REFRESHDELAY=1 # How long delay in seconds between each reload (num)
DATEBINDIR="/bin/" # Directory where your 'date' binary is. Default should be fine for most people
SETMETHOD="speedwm -s" # Method used to set the status bar
SEPARATOR="❰" # Separator to use. Alternative separators: "❰", "<", "|"
COLORFG=true # Color foreground (true/false)
COLORBG=false # Color background (true/false)
CLICKABLE=true # Enable clickability (Requires dwm with statuscmd or speedwm) (true/false)
CHARLIMIT=auto # Limit characters to CHARLIMIT. Enter false to not have a limit. Enter auto to use xdpyinfo. (num/auto/false)
ITEM_ORDER="@2 @3 @11 @4 @1 @6 @8 @5 @9 @7 @10" # Item order. @1 means item 1, @6 means item 6 and so on. (text)
# Status bar modules
# Set to true/false to enable/disable.
# Keep in mind, if the dependencies are not installed, then they will not be used regardless of what the option is set to.
ENABLE_ITEM1=true # Enable RAM usage (true/false)
ENABLE_ITEM2=true # Enable Time (HH:MM) (true/false)
ENABLE_ITEM3=true # Enable Date (DD/MM/YY) (true/false)
ENABLE_ITEM4=true # Enable Volume/Mute status (<perc>%) (true/false)
ENABLE_ITEM5=true # Enable Weather (true/false)
ENABLE_ITEM6=true # Enable Network Traffic (<num>B/s (true/false)
ENABLE_ITEM7=true # Enable dfmpeg status (true/false)
ENABLE_ITEM8=true # Enable CPU temp (true/false)
ENABLE_ITEM9=true # Enable music status (true/false)
ENABLE_ITEM10=false # Enable newsboat unread (true/false)
ENABLE_ITEM11=true # Enable battery percentage and charging status (true/false)
ITEM1_ICON=" " # Icon for ITEM1
ITEM2_ICON=" " # Icon for ITEM2
ITEM3_ICON=" " # Icon for ITEM3
ITEM4_ICON=" " # Icon for ITEM4
ITEM5_ICON=" " # Icon for ITEM5
ITEM6_ICON=" " # Icon for ITEM6
ITEM7_ICON=" " # Icon for ITEM7
ITEM8_ICON=" " # Icon for ITEM8
ITEM9_ICON=" " # Icon for ITEM9
ITEM10_ICON=" " # Icon for ITEM10
ITEM11_ICON=" " # Icon for ITEM11
# RAM format
# Format to display the RAM status in
#
# @u - Used RAM
# @t - Total RAM
#
# Example: @u/@t
ITEM1_FORMAT="@u/@t"
# Time format
# Format to display the time in
#
# @h - Hour
# @m - Minute
# @s - Second
#
# Example: @h:@m
ITEM2_FORMAT="@h:@m"
# Date format
# Format to display the date in
#
# @d - Day
# @m - Month
# @y - Year
#
# Example: @d/@m/@y
ITEM3_FORMAT="@d/@m/@y"
ITEM4_SHOW_MUTE="true" # Show mute status (true/false)
ITEM4_MUTE_TEXT="(Muted)" # Text to display when muted (text)
ITEM7_RECORDING_TEXT="Recording" # Text to display when recording (text)
ITEM8_FORMAT_CELSIUS="true" # Format temperature in Celsius (true/false)
ITEM9_BACKEND="auto" # Backend for the music status (cmus/mocp/auto)
ITEM9_DISPLAY_ARTIST="true" # Display artist or not (true/false)
ITEM9_DISPLAY_TITLE="true" # Display title or not (true/false)
ITEM9_DISPLAY_ALBUM="true" # Display album or not (true/false)
ITEM9_DISPLAY_GENRE="true" # Display genre or not (true/false)
ITEM9_DISPLAY_TIMEELAPSED="true" # Display time elapsed or not. If you use this, you will probably want the delay set pretty low. (true/false)
ITEM9_DISPLAY_TIMETOTAL="true" # Display total time or not (true/false_
ITEM9_DISPLAY_FILE="false" # Display filename or not. This option will disable everything else. Path and file extension will be cut. (true/false)
# Music format
# Format to display the music status in
#
# @a - Artist
# @t - Title
# @g - Genre
# @ab - Album
# @tt - Total time
# @te - Time elapsed
#
# Example: @a - @t from @ab (@g) [@te/@tt]
ITEM9_FORMAT="@a - @t from @ab (@g) [@te/@tt]"
ITEM10_TEXT="unread articles!" # Text to display next to unread article count (text)
ITEM11_SHOW_CHARGING_STATUS=true # Show 'Charging', 'Not charging' or 'Fully charged' status after the percentage. (true/false)
ITEM11_DISCHARGING_TEXT="Not charging" # Text when not charging (text)
ITEM11_CHARGING_TEXT="Charging" # Text when charging (text)
ITEM11_FULL_TEXT="Fully charged" # Text when fully charged (text)
EOF
. $HOME/.config/speedwm-de/status/config && echo "Created configuration file"
else
. $HOME/.config/speedwm-de/status/config && echo "Loaded configuration file"
fi
#########################################################################
# set version
if [ -e "/usr/share/speedwm/speedwm-version" ]; then
VER="$(cat /usr/share/speedwm/speedwm-version)"
else
VER="1.0"
fi
# set status
setstatus() {
$SETMETHOD "$@"
return
}
# set loading status
setloading() {
$SETMETHOD "Loading"
return
}
# print data
print() {
setstatus "$(printf "$ITEMS_TEXT")"
}
# set status2d compatible colors
setcolors2d() {
if [ "$COLORFG" = "true" ]; then
FSETCOLORCMD1="^C1^"
FSETCOLORCMD2="^C2^"
FSETCOLORCMD3="^C3^"
FSETCOLORCMD4="^C4^"
FSETCOLORCMD5="^C5^"
FSETCOLORCMD6="^C6^"
FSETCOLORCMD7="^C7^"
FSETCOLORCMD8="^C8^"
FSETCOLORCMD9="^C9^"
FSETCOLORCMD10="^C10^"
FSETCOLORCMD11="^C11^"
FSETCOLORCMD12="^C12^"
FSETCOLORCMD13="^C13^"
FSETCOLORCMD14="^C14^"
FSETCOLORCMD15="^C15^"
fi
if [ "$COLORBG" = "true" ]; then
BSETCOLORCMD1="^B1^"
BSETCOLORCMD2="^B2^"
BSETCOLORCMD3="^B3^"
BSETCOLORCMD4="^B4^"
BSETCOLORCMD5="^B5^"
BSETCOLORCMD6="^B6^"
BSETCOLORCMD7="^B7^"
BSETCOLORCMD8="^B8^"
BSETCOLORCMD9="^B9^"
BSETCOLORCMD10="^B10^"
BSETCOLORCMD11="^B11^"
BSETCOLORCMD12="^B12^"
BSETCOLORCMD13="^B13^"
BSETCOLORCMD14="^B14^"
BSETCOLORCMD15="^B15^"
fi
}
# remove old data
rm -f /tmp/itest
rm -f /tmp/wstatus
rm -f /tmp/iscelsius
mkdir -p $HOME/.config/speedwm-de/status
printf "Loaded $0 $VER\n---\n"
# Set it to /usr/bin if it was not possible to get it through /usr/share/speedwm-bindir
case "$BINDIR" in
"") BINDIR="$(dirname $(command -v status))/" ;;
esac
# RAM usage
ITEM1() {
module_ram --print &
if [ -e "/tmp/module_ram" ]; then
cat /tmp/module_ram
fi
}
# Time
ITEM2() {
module_time --print &
if [ -e "/tmp/module_time" ]; then
cat /tmp/module_time
fi
}
# Date
ITEM3() {
module_date --print &
if [ -e "/tmp/module_date" ]; then
cat /tmp/module_date
fi
}
# Volume
ITEM4() {
module_vol --print &
if [ -e "/tmp/module_vol" ]; then
cat /tmp/module_vol
fi
}
# Weather
ITEM5() {
module_weather --print &
if [ -e "/tmp/module_weather" ]; then
cat /tmp/module_weather
fi
}
# Network traffic
ITEM6() {
module_net --print &
if [ -e "/tmp/module_net" ]; then
cat /tmp/module_net
fi
}
# Dfmpeg status
ITEM7() {
module_dfmpeg --print &
if [ -e "/tmp/module_dfmpeg" ]; then
cat /tmp/module_dfmpeg
fi
}
# CPU temp
ITEM8() {
module_temp --print &
if [ -e "/tmp/module_temp" ]; then
cat /tmp/module_temp
fi
}
# mocp/cmus status
ITEM9() {
module_music --print &
if [ -e "/tmp/module_music" ]; then
cat /tmp/module_music
fi
}
# Newsboat unreads
ITEM10() {
module_news --print &
if [ -e "/tmp/module_news" ]; then
cat /tmp/module_news
fi
}
# Battery percentage/charging status
ITEM11() {
module_bat --print &
if [ -e "/tmp/module_bat" ]; then
cat /tmp/module_bat
fi
}
# Set text variables that we can print later
ptext() {
# Output of commands
# We're doing this so we can manipulate them easily for various reasons.
itemcmd1="$(echo "$(ITEM1)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd2="$(echo "$(ITEM2)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd3="$(echo "$(ITEM3)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd4="$(echo "$(ITEM4)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd5="$(echo "$(ITEM5)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd6="$(echo "$(ITEM6)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd7="$(echo "$(ITEM7)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd8="$(echo "$(ITEM8)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd9="$(echo "$(ITEM9)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd10="$(echo "$(ITEM10)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd11="$(echo "$(ITEM11)" | sed ':a;N;$!ba;s/\n//g')"
# Add colors to them
itemcmd1="$FSETCOLORCMD7$BSETCOLORCMD7$itemcmd1"
itemcmd2="$FSETCOLORCMD11$BSETCOLORCMD11$itemcmd2"
itemcmd3="$FSETCOLORCMD10$BSETCOLORCMD10$itemcmd3"
itemcmd4="$FSETCOLORCMD8$BSETCOLORCMD8$itemcmd4"
itemcmd5="$FSETCOLORCMD3$BSETCOLORCMD3$itemcmd5"
itemcmd6="$FSETCOLORCMD6$BSETCOLORCMD6$itemcmd6"
itemcmd7="$FSETCOLORCMD5$BSETCOLORCMD5$itemcmd7"
itemcmd8="$FSETCOLORCMD4$BSETCOLORCMD4$itemcmd8"
itemcmd9="$FSETCOLORCMD2$BSETCOLORCMD2$itemcmd9"
itemcmd10="$FSETCOLORCMD9$BSETCOLORCMD9$itemcmd10"
itemcmd11="$FSETCOLORCMD8$BSETCOLORCMD8$itemcmd11"
# Clickability
if [ "$CLICKABLE" = "true" ]; then
ITEMS_TEXT="$(echo "$ITEM_ORDER" | sed "s|@10|\x10$itemcmd10|; s|@11|\x11$itemcmd11|; s|@1|\x01$itemcmd1|; s|@2|\x02$itemcmd2|; s|@3|\x03$itemcmd3|; s|@4|\x04$itemcmd4|; s|@5|\x05$itemcmd5|; s|@6|\x06$itemcmd6|; s|@7|\x07$itemcmd7|; s|@8|\x08$itemcmd8|; s|@9|\x09$itemcmd9|; s|%|%%|g")"
else
ITEMS_TEXT="$(echo "$ITEM_ORDER" | sed "s|@10|$itemcmd10|; s|@11|$itemcmd11|; s|@1|$itemcmd1|; s|@2|$itemcmd2|; s|@3|$itemcmd3|; s|@4|$itemcmd4|; s|@5|$itemcmd5|; s|@6|$itemcmd6|; s|@7|$itemcmd7|; s|@8|$itemcmd8|; s|@9|$itemcmd9|; s|%|%%|g")"
fi
# Auto-get character limit based on screen resolution
# This is pretty hacky, but it works as a default.
# Setting this to "false" is recommended if you've got a big monitor
# I think the first three numbers of your screen resolution times 1.5 is a good max.
# I've got a 1366x768 12 inch ThinkPad so I decided to implement this.
# If anyone has a better method, please PR.
if [ "$CHARLIMIT" = "auto" ]; then
command -v xdpyinfo > /dev/null && \
RES="$(xdpyinfo | awk '/dimensions/ {print $2}' | sed 's/.x....*//g; s/[^0-9]*//g')"
CHARS="$(expr "$RES" "*" "1")"
if [ "$CHARS" = "" ]; then
CHARS=false
fi
elif [ "$CHARLIMIT" != "false" ]; then
CHARS=$CHARLIMIT
else
CHARS=false
fi
if [ "$CHARS" != "false" ]; then
# Truncate item 11
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd11=""
# Truncate item 10
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd10=""
# Truncate item 9
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd9=""
# Truncate item 8
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd8=""
# Truncate item 7
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd7=""
# Truncate item 6
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd6=""
# Truncate item 5
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd5=""
# Truncate item 4
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd4=""
# Truncate item 3
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd3=""
# Truncate item 2
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd2=""
# Truncate item 1
if [ "$(printf $itemcmd1$itemcmd2$itemcmd3$itemcmd4$itemcmd5$itemcmd6$itemcmd7$itemcmd8$itemcmd9$itemcmd10$itemcmd11 | wc -c)" -gt "$CHARS" ]; then
itemcmd1=""
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
print
pgrep -x speedwm > /dev/null || exit 1
}
# base
base() {
ptext
sleep $REFRESHDELAY
base
}
setloading
setcolors2d
ptext
base
printf "$0: Stopped printing."
exit 0