Browse Source

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
main
joestandring 5 years ago
parent
commit
b91de22538
10 changed files with 117 additions and 37 deletions
  1. +16
    -3
      README.md
  2. +6
    -2
      dwm_bar.sh
  3. +20
    -7
      functions/dwm_alsa.sh
  4. +27
    -12
      functions/dwm_cmus.sh
  5. +12
    -3
      functions/dwm_countdown.sh
  6. +6
    -1
      functions/dwm_date.sh
  7. +6
    -1
      functions/dwm_keyboard.sh
  8. +9
    -3
      functions/dwm_mail.sh
  9. +9
    -4
      functions/dwm_resources.sh
  10. +6
    -1
      functions/dwm_weather.sh

+ 16
- 3
README.md View File

@ -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

+ 6
- 2
dwm_bar.sh View File

@ -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)"


+ 20
- 7
functions/dwm_alsa.sh View File

@ -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

+ 27
- 12
functions/dwm_cmus.sh View File

@ -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" <span class="s2">"</span>$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

+ 12
- 3
functions/dwm_countdown.sh View File

@ -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

+ 6
- 1
functions/dwm_date.sh View File

@ -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

+ 6
- 1
functions/dwm_keyboard.sh View File

@ -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

+ 9
- 3
functions/dwm_mail.sh View File

@ -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

+ 9
- 4
functions/dwm_resources.sh View File

@ -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

+ 6
- 1
functions/dwm_weather.sh View File

@ -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

Loading…
Cancel
Save