From 4e69403057cbe31e267d6928849958a25c84ada9 Mon Sep 17 00:00:00 2001 From: joestandring Date: Mon, 6 May 2019 21:11:01 +0000 Subject: [PATCH] Initial commit --- README.md | 6 ++++++ TODO | 6 ++++++ dwm_bar.sh | 30 ++++++++++++++++++++++++++++++ functions/dwm_alsa.sh | 21 +++++++++++++++++++++ functions/dwm_cmus.sh | 36 ++++++++++++++++++++++++++++++++++++ functions/dwm_countdown.sh | 14 ++++++++++++++ functions/dwm_date.sh | 11 +++++++++++ functions/dwm_keyboard.sh | 12 ++++++++++++ functions/dwm_mail.sh | 17 +++++++++++++++++ functions/dwm_resources.sh | 20 ++++++++++++++++++++ functions/dwm_weather.sh | 14 ++++++++++++++ 11 files changed, 187 insertions(+) create mode 100644 TODO create mode 100755 dwm_bar.sh create mode 100755 functions/dwm_alsa.sh create mode 100755 functions/dwm_cmus.sh create mode 100755 functions/dwm_countdown.sh create mode 100755 functions/dwm_date.sh create mode 100755 functions/dwm_keyboard.sh create mode 100755 functions/dwm_mail.sh create mode 100755 functions/dwm_resources.sh create mode 100755 functions/dwm_weather.sh diff --git a/README.md b/README.md index 129308c..008b0f4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,8 @@ # dwm-bar A modular statusbar for DWM thrown together in sh +## Acknowledgements +Code for some functions was modified from: +* [Klemens Nanni](https://notabug.org/kl3) +* [@boylemic](https://github.com/boylemic/configs/blob/master/dwm_status) +* [Parket Johnson](https://github.com/ronno/scripts/blob/master/xsetcmus) +* [suckless.org](https://dwm.suckless.org/status_monitor/) diff --git a/TODO b/TODO new file mode 100644 index 0000000..c1da5f5 --- /dev/null +++ b/TODO @@ -0,0 +1,6 @@ +Show SSID in dwm_network +dwm_bat function +Network speeds +dwm_pulse function +dwm_notifs function +Swappable unicode and plaintext module identifiers diff --git a/dwm_bar.sh b/dwm_bar.sh new file mode 100755 index 0000000..f2935c9 --- /dev/null +++ b/dwm_bar.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# A modular status bar for dwm +# Joe Standring +# GNU GPLv3 + +# 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" + +# Store the directory the script is running from +LOC=$(readlink -f "$0") +DIR=$(dirname "$LOC") + +# Import the modules +. "$DIR/functions/dwm_countdown.sh" +. "$DIR/functions/dwm_cmus.sh" +. "$DIR/functions/dwm_resources.sh" +. "$DIR/functions/dwm_mail.sh" +. "$DIR/functions/dwm_alsa.sh" +. "$DIR/functions/dwm_weather.sh" +. "$DIR/functions/dwm_date.sh" + +# Update dwm's status bar every second +while true +do + xsetroot -name "$(dwm_countdown)$(dwm_cmus)$(dwm_resources)$(dwm_mail)$(dwm_alsa)$(dwm_weather)$(dwm_date)" + sleep 1 +done diff --git a/functions/dwm_alsa.sh b/functions/dwm_alsa.sh new file mode 100755 index 0000000..d39d730 --- /dev/null +++ b/functions/dwm_alsa.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# A dwm_bar function to show the master volume of ALSA +# Joe Standring +# GNU GPLv3 + +# Dependencies: alsa-utils + +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" + else + printf "[\U1F50A $VOL]\n" + fi +} +dwm_alsa diff --git a/functions/dwm_cmus.sh b/functions/dwm_cmus.sh new file mode 100755 index 0000000..d745721 --- /dev/null +++ b/functions/dwm_cmus.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# A dwm_bar function that shows the current artist, track, position, duration, and status from cmus +# Joe Standring +# GNU GPLv3 + +# Dependencies: cmus + +dwm_cmus () { + if ps -C cmus > /dev/null; then + ARTIST=$(cmus-remote -Q | grep -a '^tag artist' | awk '{gsub("tag artist ", "");print}') + TRACK=$(cmus-remote -Q | grep -a '^tag title' | awk '{gsub("tag title ", "");print}') + POSITION=$(cmus-remote -Q | grep -a '^position' | awk '{gsub("position ", "");print}') + DURATION=$(cmus-remote -Q | grep -a '^duration' | awk '{gsub("duration ", "");print}') + 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 [ $SHUFFLE == "true" ]; then + SHUFFLE=" \U1F500" + else + SHUFFLE="" + fi + + printf "[$STATUS $ARTIST - $TRACK " + printf "%0d:%02d/" $(($POSITION%3600/60)) $(($POSITION%60)) + printf "%0d:%02d" $(($DURATION%3600/60)) $(($DURATION%60)) + printf "$SHUFFLE]\n" + fi +} +dwm_cmus diff --git a/functions/dwm_countdown.sh b/functions/dwm_countdown.sh new file mode 100755 index 0000000..58dfa59 --- /dev/null +++ b/functions/dwm_countdown.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# A dwm_status function that displays the status of countdown.sh +# Joe Standring +# GNU GPLv3 + +# Dependencies: https://github.com/joestandring/countdown + +dwm_countdown () { + if [ -e /tmp/countdown.* ]; then + printf "[\U23F3 $(tail -1 /tmp/countdown.*)]" + fi +} +dwm_countdown diff --git a/functions/dwm_date.sh b/functions/dwm_date.sh new file mode 100755 index 0000000..034ac2b --- /dev/null +++ b/functions/dwm_date.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# A dwm_bar function that shows the current date and time +# Joe Standring +# GNU GPLv3 + +# Date is formatted like like this: "[Mon 01-01-00 00:00:00]" +dwm_date () { + printf "[\U23F2 $(date "+%a %d-%m-%y %T")]\n" +} +dwm_date diff --git a/functions/dwm_keyboard.sh b/functions/dwm_keyboard.sh new file mode 100755 index 0000000..943a8ec --- /dev/null +++ b/functions/dwm_keyboard.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +# A dwm_bar function that displays the current keyboard layout +# Joe Standring +# GNU GPLv3 + +# Dependencies: xorg-setxkbmap + +dwm_keyboard () { + printf "[\U2328 $(setxkbmap -query | awk '/layout/{print $2}')]\n" +} +dwm_keyboard diff --git a/functions/dwm_mail.sh b/functions/dwm_mail.sh new file mode 100755 index 0000000..b994677 --- /dev/null +++ b/functions/dwm_mail.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# A dwm_bar function to display the number of emails in an inbox +# Joe Standring +# GNU GPLv3 + +# To count mail in an inbox, change "/path/to/inbox" below to the location of your inbox. For example, "/home/$USER/.mail/new" + +dwm_mail () { + MAILBOX=$(ls /path/to/inbox | wc -l) + if [ $MAILBOX -eq 0 ]; then + printf "[\U1F4ED $MAILBOX]\n" + else + printf "[\U1F4EB $MAILBOX]\n" + fi +} +dwm_mail diff --git a/functions/dwm_resources.sh b/functions/dwm_resources.sh new file mode 100755 index 0000000..aad2bf9 --- /dev/null +++ b/functions/dwm_resources.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# A dwm_bar function to display information regarding system memory, CPU temperature, and storage +# Joe Standring +# GNU GPLv3 + +dwm_resources () { + # Used and total memory + MEMUSED=$(free -h | awk '(NR == 2) {print $3}') + MEMTOT=$(free -h |awk '(NR == 2) {print $2}') + # 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 $2}') + STOTOT=$(df -h | grep '/home' | awk '{print $3}') + STOPER=$(df -h | grep '/home' | awk '{print $5}') + + printf "[\U1F5A5 MEM $MEMUSED/$MEMTOT CPU $CPU STO $STOUSED/$STOTOT: $STOPER%]\n" +} +dwm_resources diff --git a/functions/dwm_weather.sh b/functions/dwm_weather.sh new file mode 100755 index 0000000..5b23ac5 --- /dev/null +++ b/functions/dwm_weather.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# A dwm_bar function to print the weather from wttr.in +# Joe Standring +# GNU GPLv3 + +# Dependencies: curl + +# Change the value of LOCATION to match your city +dwm_weather() { + LOCATION=city + printf "[$(curl -s wttr.in/$LOCATION?format=1)]\n" +} +dwm_weather