speedwm-personal/scripts/speedwm-stellar
2022-11-03 15:17:20 +01:00

448 lines
12 KiB
Bash
Executable file

#!/bin/sh
# stellar - 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/status/config instead though
# All settings can be changed there. Otherwise, carefully edit the file and recompile speedwm!
if [ ! -e "$HOME/.config/speedwm/statusrc" ]; then
cat <<CONFIG > ~/.config/speedwm/statusrc
# speedwm status configuration
#
# NOTE: Should be configured in /bin/sh compatible syntax. For best compatibility, I suggest that you only use POSIX compliant shell. No bash, no fish and no zsh. Of course if /bin/sh is Bash then you don't strictly NEED to keep it POSIX compliant.
# 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. speedwm -s will set the status so only change this if you use this status bar with dwm or awesome.
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)
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> kb/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)
# Net format
# Format to display the transmitted/received bytes in
#
# @t - Transmitted
# @r - Received
#
# Example: @t kb/s
ITEM6_FORMAT="@t kb/s"
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)
CONFIG
. $HOME/.config/speedwm/statusrc && echo "Created configuration file"
else
. $HOME/.config/speedwm/statusrc && 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() {
pgrep -x speedwm > /dev/null || return
$SETMETHOD "$@"
return
}
# set loading status
setloading() {
$SETMETHOD "Loading"
return
}
# print data
print() {
setstatus "$(printf "$ITEMS_TEXT" | sed "s/stellar_amp/\&/g")"
}
# 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
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 speedwm_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.
if [ "$ENABLE_ITEM1" = "true" ]; then
if [ "$(ITEM1)" != "" ]; then
itemcmd1="$(echo "$(ITEM1)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd1="$FSETCOLORCMD7$BSETCOLORCMD7 $itemcmd1"
else
itemcmd1=""
fi
fi
if [ "$ENABLE_ITEM2" = "true" ]; then
if [ "$(ITEM2)" != "" ]; then
itemcmd2="$(echo "$(ITEM2)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd2="$FSETCOLORCMD11$BSETCOLORCMD11 $itemcmd2"
else
itemcmd2=""
fi
fi
if [ "$ENABLE_ITEM3" = "true" ]; then
if [ "$(ITEM3)" != "" ]; then
itemcmd3="$(echo "$(ITEM3)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd3="$FSETCOLORCMD10$BSETCOLORCMD10 $itemcmd3"
else
itemcmd3=""
fi
fi
if [ "$ENABLE_ITEM4" = "true" ]; then
if [ "$(ITEM4)" != "" ]; then
itemcmd4="$(echo "$(ITEM4)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd4="$FSETCOLORCMD8$BSETCOLORCMD8 $itemcmd4"
else
itemcmd4=""
fi
fi
if [ "$ENABLE_ITEM5" = "true" ]; then
if [ "$(ITEM5)" != "" ]; then
itemcmd5="$(echo "$(ITEM5)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd5="$FSETCOLORCMD3$BSETCOLORCMD3 $itemcmd5"
else
itemcmd5=""
fi
fi
if [ "$ENABLE_ITEM6" = "true" ]; then
if [ "$(ITEM6)" != "" ]; then
itemcmd6="$(echo "$(ITEM6)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd6="$FSETCOLORCMD6$BSETCOLORCMD6 $itemcmd6"
else
itemcmd6=""
fi
fi
if [ "$ENABLE_ITEM7" = "true" ]; then
if [ "$(ITEM7)" != "" ]; then
itemcmd7="$(echo "$(ITEM7)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd7="$FSETCOLORCMD5$BSETCOLORCMD5 $itemcmd7"
else
itemcmd7=""
fi
fi
if [ "$ENABLE_ITEM8" = "true" ]; then
if [ "$(ITEM8)" != "" ]; then
itemcmd8="$(echo "$(ITEM8)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd8="$FSETCOLORCMD4$BSETCOLORCMD4 $itemcmd8"
else
itemcmd8=""
fi
fi
if [ "$ENABLE_ITEM9" = "true" ]; then
if [ "$(ITEM9)" != "" ]; then
itemcmd9="$(echo "$(ITEM9)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd9="$FSETCOLORCMD2$BSETCOLORCMD2 $itemcmd9"
else
itemcmd9=""
fi
fi
if [ "$ENABLE_ITEM10" = "true" ]; then
if [ "$(ITEM10)" != "" ]; then
itemcmd10="$(echo "$(ITEM10)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd10="$FSETCOLORCMD9$BSETCOLORCMD9 $itemcmd10"
else
itemcmd10=""
fi
fi
if [ "$ENABLE_ITEM11" = "true" ]; then
if [ "$(ITEM11)" != "" ]; then
itemcmd11="$(echo "$(ITEM11)" | sed ':a;N;$!ba;s/\n//g')"
itemcmd11="$FSETCOLORCMD8$BSETCOLORCMD8 $itemcmd11"
else
itemcmd11=""
fi
fi
# Clickability
if [ "$CLICKABLE" = "true" ]; then
ITEMS_TEXT="$(echo "$ITEM_ORDER" | sed "s/^[[:space:]]*//g; 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/^[[:space:]]*//g; 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
print
}
# base
base() {
ptext
sleep $REFRESHDELAY
base
}
setloading
setcolors2d
ptext
base
printf "$0: Stopped printing."
exit 0