From b91de22538b9b445aae995a26003ae52c1de7d9c Mon Sep 17 00:00:00 2001 From: joestandring Date: Mon, 20 May 2019 20:52:52 +0000 Subject: [PATCH] Added unicode/plaintext toggle - Added the $IDENTIFIER value that determines if unicode or plaintext is used for function identifiers - Cleaned up scripts with the help of shellchecker - Fixed dwm_status so that other drives mounted within /home are ignored - Replaced unicode codes with actual unicode in the source. For some reason the codes didnt work on my Void machine - Updated readme --- README.md | 19 ++++++++++++++++--- dwm_bar.sh | 8 ++++++-- functions/dwm_alsa.sh | 27 +++++++++++++++++++------- functions/dwm_cmus.sh | 39 ++++++++++++++++++++++++++------------ functions/dwm_countdown.sh | 15 ++++++++++++--- functions/dwm_date.sh | 7 ++++++- functions/dwm_keyboard.sh | 7 ++++++- functions/dwm_mail.sh | 12 +++++++++--- functions/dwm_resources.sh | 13 +++++++++---- functions/dwm_weather.sh | 7 ++++++- 10 files changed, 117 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 7d9a141..2a010dc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # dwm-bar A modular statusbar for DWM -![screenshot](dwm-bar.png) ## Table of Contents +- [Features](#features) - [Current Functions](#current-functions) - [dwm_alsa](#dwm_alsa) - [dwm_countdown](#dwm_countdown) @@ -16,6 +16,10 @@ A modular statusbar for DWM - [Customizing](#customizing) - [Acknowledgements](#acknowledgements) - [More to come!](#more-to-come) +## Features +* Fully modular! If you don't want to use a function, no worries. +* Lightweight! dwm-bar is written entirely in POSIX-compliant shell script so need to install a hundred different packages to get it working. +* Options! You can decide to use either unicode symbols or plaintext for module identifiers with the ```IDENTIFIER``` value. ## Current Functions ### dwm_alsa Displays the current master volume of ALSA @@ -71,11 +75,12 @@ $ cd dwm-bar ``` $ chmod +x dwm_bar.sh ``` -## Usage +## Quick Start Simply run the script and dwm should display your bar: ``` $ ./dwm_bar.sh ``` +Most likely, you will need to change some values for functions to get them to work - these are outlined with a comment for functions where this is likely the case. If you would like your bar to be displayed when X starts, add this to your .xinitrc file before launching dwm. For example, if the script is located in /home/$USER/dwm-bar/: ``` # Statusbar @@ -97,6 +102,14 @@ do sleep 1 done ``` +You can also decide to use unicode or plaintext identifiers for functions by altering the ```$IDENTIFIER``` value. For example, set to ```"unicode"```, ```dwm_mail``` will display: +``` +[📫 0] +``` +Whereas, if it is not set it will display: +``` +[MAI 0] +``` ## Acknowledgements Code for some functions was modified from: * [Klemens Nanni](https://notabug.org/kl3) @@ -104,8 +117,8 @@ Code for some functions was modified from: * [Parket Johnson](https://github.com/ronno/scripts/blob/master/xsetcmus) * [suckless.org](https://dwm.suckless.org/status_monitor/) ## More to come! -* Ability to choose between showing unicode charachters or plaintext for identifiers in the bar * dwm_pulse function to control pulseaudio sound * dwm_bat function to display battery percentage and status * dwm_notifs function to show the last recieved notification in the bar +* dwm_bluez function to show currently connected Bluetooth device using bluez * The ability to show network speeds and SSID in dwm_network diff --git a/dwm_bar.sh b/dwm_bar.sh index 195c1e5..ee46e88 100755 --- a/dwm_bar.sh +++ b/dwm_bar.sh @@ -7,12 +7,16 @@ # Dependencies: xorg-xsetroot # Import functions with "$include /route/to/module" -# It is reccomended that you place functions in the subdirectory ./functions and use: . "$DIR/modules/dwm_example.sh" +# It is recommended that you place functions in the subdirectory ./functions and use: . "$DIR/modules/dwm_example.sh" # Store the directory the script is running from LOC=$(readlink -f "$0") DIR=$(dirname "$LOC") +# Change the appearance of the module identifier. if this is set to "unicode", then symbols will be used as identifiers instead of text. E.g. [📪 0] instead of [MAIL 0]. +# Requires a font with adequate unicode character support +#export IDENTIFIER="unicode" + # Import the modules . "$DIR/functions/dwm_countdown.sh" . "$DIR/functions/dwm_cmus.sh" @@ -23,7 +27,7 @@ DIR=$(dirname "$LOC") . "$DIR/functions/dwm_keyboard.sh" . "$DIR/functions/dwm_date.sh" -# Update dwm's status bar every second +# Update dwm status bar every second while true do xsetroot -name "$(dwm_countdown)$(dwm_cmus)$(dwm_resources)$(dwm_mail)$(dwm_alsa)$(dwm_weather)$(dwm_keyboard)$(dwm_date)" diff --git a/functions/dwm_alsa.sh b/functions/dwm_alsa.sh index 1d694bb..5fc8bcb 100755 --- a/functions/dwm_alsa.sh +++ b/functions/dwm_alsa.sh @@ -8,14 +8,27 @@ dwm_alsa () { VOL=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/") - if [ $VOL -eq 0 ]; then - printf "[\U1F507 $VOL]\n" - elif [ $VOL -gt 0 ] && [ $VOL -le 33 ]; then - printf "[\U1F508 $VOL]\n" - elif [ $VOL -gt 33 ] && [ $VOL -le 66 ]; then - printf "[\U1F509 $VOL]\n" + if [ "$IDENTIFIER" = "unicode" ]; then + if [ "$VOL" -eq 0 ]; then + printf "[🔇 %s]\n" "$VOL]\n" + elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then + printf "[🔈 %s]\n" "$VOL" + elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then + printf "[🔉 %s]\n" "$VOL" + else + printf "[🔊 %s]\n" "$VOL" + fi else - printf "[\U1F50A $VOL]\n" + if [ "$VOL" -eq 0 ]; then + printf "[VOL %s]\n" "$VOL]\n" + elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then + printf "[VOL %s]\n" "$VOL" + elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then + printf "[VOL %s]\n" "$VOL" + else + printf "[VOL %s]\n" "$VOL" + fi fi } + dwm_alsa diff --git a/functions/dwm_cmus.sh b/functions/dwm_cmus.sh index db13653..2b8294c 100755 --- a/functions/dwm_cmus.sh +++ b/functions/dwm_cmus.sh @@ -15,22 +15,37 @@ dwm_cmus () { STATUS=$(cmus-remote -Q | grep -a '^status' | awk '{gsub("status ", "");print}') SHUFFLE=$(cmus-remote -Q | grep -a '^set shuffle' | awk '{gsub("set shuffle ", "");print}') - if [ $STATUS == "playing" ]; then - STATUS="\U25B6" - else - STATUS="\U23F8" - fi + if [ "$IDENTIFIER" = "unicode" ]; then + if [ "$STATUS" = "playing" ]; then + STATUS="▶" + else + STATUS="⏸" + fi - if [ $SHUFFLE == "true" ]; then - SHUFFLE=" \U1F500" + if [ "$SHUFFLE" = "true" ]; then + SHUFFLE=" 🔀" + else + SHUFFLE="" + fi else - SHUFFLE="" + if [ "$STATUS" = "playing" ]; then + STATUS="PLA" + else + STATUS="PAU" + fi + + if [ "$SHUFFLE" = "true" ]; then + SHUFFLE=" S" + else + SHUFFLE="" + fi fi - printf "[$STATUS $ARTIST - $TRACK " - printf "%0d:%02d/" $(($POSITION%3600/60)) $(($POSITION%60)) - printf "%0d:%02d" $(($DURATION%3600/60)) $(($DURATION%60)) - printf "$SHUFFLE]\n" + printf "[%s %s - %s " "$STATUS" "$ARTIST" "$TRACK" + printf "%0d:%02d/" $((POSITION%3600/60)) $((POSITION%60)) + printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60)) + printf "%s]\n" "$SHUFFLE" fi } + dwm_cmus diff --git a/functions/dwm_countdown.sh b/functions/dwm_countdown.sh index 2403e89..7ba938e 100755 --- a/functions/dwm_countdown.sh +++ b/functions/dwm_countdown.sh @@ -7,8 +7,17 @@ # Dependencies: https://github.com/joestandring/countdown dwm_countdown () { - if [ -e /tmp/countdown.* ]; then - printf "[\U23F3 $(tail -1 /tmp/countdown.*)]" - fi + for f in /tmp/countdown.*; do + if [ -e "$f" ]; then + if [ "$IDENTIFIER" = "unicode" ]; then + printf "[⏳ %s]\n" "$(tail -1 /tmp/countdown.*)" + else + printf "[CDN %s]\n" "$(tail -1 /tmp/countdown.*)" + fi + + break + fi + done } + dwm_countdown diff --git a/functions/dwm_date.sh b/functions/dwm_date.sh index 7ccef71..4550fa2 100755 --- a/functions/dwm_date.sh +++ b/functions/dwm_date.sh @@ -6,6 +6,11 @@ # Date is formatted like like this: "[Mon 01-01-00 00:00:00]" dwm_date () { - printf "[\U23F2 $(date "+%a %d-%m-%y %T")]\n" + if [ "$IDENTIFIER" = "unicode" ]; then + printf "[📆 %s]\n" "$(date "+%a %d-%m-%y %T")" + else + printf "[DAT %s]\n" "$(date "+%a %d-%m-%y %T")" + fi } + dwm_date diff --git a/functions/dwm_keyboard.sh b/functions/dwm_keyboard.sh index 0216263..686afb6 100755 --- a/functions/dwm_keyboard.sh +++ b/functions/dwm_keyboard.sh @@ -7,6 +7,11 @@ # Dependencies: xorg-setxkbmap dwm_keyboard () { - printf "[\U2328 $(setxkbmap -query | awk '/layout/{print $2}')]\n" + if [ "$IDENTIFIER" = "unicode" ]; then + printf "[⌨ %s]\n" "$(setxkbmap -query | awk '/layout/{print $2}')" + else + printf "[KEY %s]\n" "$(setxkbmap -query | awk '/layout/{print $2}')" + fi } + dwm_keyboard diff --git a/functions/dwm_mail.sh b/functions/dwm_mail.sh index 3766929..c50ee90 100755 --- a/functions/dwm_mail.sh +++ b/functions/dwm_mail.sh @@ -8,10 +8,16 @@ dwm_mail () { MAILBOX=$(ls /path/to/inbox | wc -l) - if [ $MAILBOX -eq 0 ]; then - printf "[\U1F4ED $MAILBOX]\n" + + if [ "$IDENTIFIER" = "unicode" ]; then + if [ "$MAILBOX" -eq 0 ]; then + printf "[📪 %s]\n" "$MAILBOX" + else + printf "[📫 %s]\n" "$MAILBOX" + fi else - printf "[\U1F4EB $MAILBOX]\n" + printf "[MAI %s]\n" "$MAILBOX" fi } + dwm_mail diff --git a/functions/dwm_resources.sh b/functions/dwm_resources.sh index 0694763..87db9bb 100755 --- a/functions/dwm_resources.sh +++ b/functions/dwm_resources.sh @@ -11,10 +11,15 @@ dwm_resources () { # CPU temperature CPU=$(sysctl -n hw.sensors.cpu0.temp0 | cut -d. -f1) # Used and total storage in /home (rounded to 1024B) - STOUSED=$(df -h | grep '/home' | awk '{print $3}') - STOTOT=$(df -h | grep '/home' | awk '{print $2}') - STOPER=$(df -h | grep '/home' | awk '{print $5}') + STOUSED=$(df -h | grep '/home$' | awk '{print $3}') + STOTOT=$(df -h | grep '/home$' | awk '{print $2}') + STOPER=$(df -h | grep '/home$' | awk '{print $5}') - printf "[\U1F5A5 MEM $MEMUSED/$MEMTOT CPU $CPU STO $STOUSED/$STOTOT: $STOPER%]\n" + if [ "$IDENTIFIER" = "unicode" ]; then + printf "[💻 MEM %s/%s CPU %s STO %s/%s: %s]\n" "$MEMUSED" "$MEMTOT" "$CPU" "$STOUSED" "$STOTOT" "$STOPER" + else + printf "[STA | MEM %s/%s CPU %s STO %s/%s: %s]\n" "$MEMUSED" "$MEMTOT" "$CPU" "$STOUSED" "$STOTOT" "$STOPER" + fi } + dwm_resources diff --git a/functions/dwm_weather.sh b/functions/dwm_weather.sh index 924f249..678475d 100755 --- a/functions/dwm_weather.sh +++ b/functions/dwm_weather.sh @@ -9,6 +9,11 @@ # Change the value of LOCATION to match your city dwm_weather() { LOCATION=city - printf "[$(curl -s wttr.in/$LOCATION?format=1)]\n" + if [ "$IDENTIFIER" = "unicode" ]; then + printf "[%s]\n" "$(curl -s wttr.in/$LOCATION?format=1)" + else + printf "[WEA %s]\n" "$(curl -s wttr.in/$LOCATION?format=1 | grep -o "[0-9].*")" + fi } + dwm_weather