From 51fd3faa1b493424dc940a6ed4543e6c9462e3b0 Mon Sep 17 00:00:00 2001 From: joestandring Date: Mon, 8 Jul 2019 09:32:22 +0100 Subject: [PATCH] Add 'SEP1' and 'SEP2' The 'SEP' contain the charachter(s) that are placed before and after a module (respectively). For example, if SEP1="[" and SEP2="]" then each module will be surrounded by those charachters. --- README.md | 10 ++-------- bar-functions/dwm_alsa.sh | 18 ++++++++++-------- bar-functions/dwm_backlight.sh | 2 +- bar-functions/dwm_battery.sh | 8 +++++--- bar-functions/dwm_ccurse.sh | 12 ++++++++---- bar-functions/dwm_cmus.sh | 4 ++-- bar-functions/dwm_countdown.sh | 6 ++++-- bar-functions/dwm_date.sh | 6 ++++-- bar-functions/dwm_keyboard.sh | 6 ++++-- bar-functions/dwm_mail.sh | 8 +++++--- bar-functions/dwm_network.sh | 6 ++++-- bar-functions/dwm_pulse.sh | 19 +++++++++++-------- bar-functions/dwm_resources.sh | 6 ++++-- bar-functions/dwm_transmission.sh | 14 ++++++++------ bar-functions/dwm_vpn.sh | 15 ++++++++------- bar-functions/dwm_weather.sh | 7 +++++-- dwm_bar.sh | 5 ++++- 17 files changed, 89 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 24a8b4c..9561ef3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ A modular statusbar for DWM ![screenshot](sshot.png) ## Table of Contents -- [Features](#features) - [Current Functions](#current-functions) - [dwm_alsa](#dwm_alsa) - [dwm_pulse](#dwm_pulse) @@ -24,11 +23,6 @@ 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 ``` @@ -139,8 +133,8 @@ If you would like your bar to be displayed when X starts, add this to your .xini exec dwm ``` ## Customizing -dwm-bar is completley modular, meaning you can mix and match functions to your hearts content. It's functions are located in the functions/ subdirectory and included in dwm_bar.sh -If you want to make your own function, for example dwm_myfunction.sh, you should create it in the functions/ subdirectory before including it in dwm_bar.sh and adding it to the xsetroot command: +dwm-bar is completley modular, meaning you can mix and match functions to your hearts content. It's functions are located in the bar-functions/ subdirectory and included in dwm_bar.sh +If you want to make your own function, for example dwm_myfunction.sh, you should create it in the bar-functions/ subdirectory before including it in dwm_bar.sh and adding it to the xsetroot command: ``` # Import the modules . "$DIR/bar-functions/dwm_myfucntion" diff --git a/bar-functions/dwm_alsa.sh b/bar-functions/dwm_alsa.sh index d670256..d96f73d 100755 --- a/bar-functions/dwm_alsa.sh +++ b/bar-functions/dwm_alsa.sh @@ -8,27 +8,29 @@ dwm_alsa () { VOL=$(amixer get Master | tail -n1 | sed -r "s/.*\[(.*)%\].*/\1/") + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then if [ "$VOL" -eq 0 ]; then - printf "šŸ”‡\n" + printf "šŸ”‡" elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then - printf "šŸ”ˆ %s%%\n" "$VOL" + printf "šŸ”ˆ %s%%" "$VOL" elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then - printf "šŸ”‰ %s%%\n" "$VOL" + printf "šŸ”‰ %s%%" "$VOL" else - printf "šŸ”Š %s%%\n" "$VOL" + printf "šŸ”Š %s%%" "$VOL" fi else if [ "$VOL" -eq 0 ]; then - printf "MUTE\n" + printf "MUTE" elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then - printf "VOL %s%%\n" "$VOL" + printf "VOL %s%%" "$VOL" elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then - printf "VOL %s%%\n" "$VOL" + printf "VOL %s%%" "$VOL" else - printf "VOL %s%%\n" "$VOL" + printf "VOL %s%%" "$VOL" fi fi + printf "%s\n" "$SEP2" } dwm_alsa diff --git a/bar-functions/dwm_backlight.sh b/bar-functions/dwm_backlight.sh index eb88792..c0968d8 100755 --- a/bar-functions/dwm_backlight.sh +++ b/bar-functions/dwm_backlight.sh @@ -7,7 +7,7 @@ # Dependencies: xbacklight dwm_backlight () { - printf "ā˜€ %.0f\n" "$(xbacklight)" + printf "%sā˜€ %.0f%s\n" "$SEP1" "$(xbacklight)" "$SEP2" } dwm_backlight diff --git a/bar-functions/dwm_battery.sh b/bar-functions/dwm_battery.sh index b26c00f..6321e64 100755 --- a/bar-functions/dwm_battery.sh +++ b/bar-functions/dwm_battery.sh @@ -9,15 +9,17 @@ dwm_battery () { CHARGE=$(cat /sys/class/power_supply/BAT1/capacity) STATUS=$(cat /sys/class/power_supply/BAT1/status) + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then if [ "$STATUS" = "Charging" ]; then - printf "šŸ”Œ %s%% %s\n" "$CHARGE" "$STATUS" + printf "šŸ”Œ %s%% %s" "$CHARGE" "$STATUS" else - printf "šŸ”‹ %s%% %s\n" "$CHARGE" "$STATUS" + printf "šŸ”‹ %s%% %s" "$CHARGE" "$STATUS" fi else - printf "BAT %s%% %s\n" "$CHARGE" "$STATUS" + printf "BAT %s%% %s" "$CHARGE" "$STATUS" fi + printf "%s\n" "$SEP2" } dwm_battery diff --git a/bar-functions/dwm_ccurse.sh b/bar-functions/dwm_ccurse.sh index 981bb1e..bbfe948 100755 --- a/bar-functions/dwm_ccurse.sh +++ b/bar-functions/dwm_ccurse.sh @@ -9,10 +9,14 @@ dwm_ccurse () { APPOINTMENT=$(calcurse -a | head -n 3 | tr -d '\n+>-' | awk '$1=$1' | sed 's/://') - if [ "$IDENTIFIER" = "unicode" ]; then - printf "šŸ’” %s\n" "$APPOINTMENT" - else - printf "APT %s\n" "$APPOINTMENT" + if [ "$APPOINTMENT" != "" ]; then + printf "%s" "$SEP1" + if [ "$IDENTIFIER" = "unicode" ]; then + printf "šŸ’” %s" "$APPOINTMENT" + else + printf "APT %s" "$APPOINTMENT" + fi + printf "%s\n" "$SEP2" fi } diff --git a/bar-functions/dwm_cmus.sh b/bar-functions/dwm_cmus.sh index 0c4595c..43f6c76 100755 --- a/bar-functions/dwm_cmus.sh +++ b/bar-functions/dwm_cmus.sh @@ -41,10 +41,10 @@ dwm_cmus () { fi fi - printf "%s %s - %s " "$STATUS" "$ARTIST" "$TRACK" + printf "%s%s %s - %s " "$SEP1" "$STATUS" "$ARTIST" "$TRACK" printf "%0d:%02d/" $((POSITION%3600/60)) $((POSITION%60)) printf "%0d:%02d" $((DURATION%3600/60)) $((DURATION%60)) - printf "%s\n" "$SHUFFLE" + printf "%s%s\n" "$SHUFFLE" "$SEP2" fi } diff --git a/bar-functions/dwm_countdown.sh b/bar-functions/dwm_countdown.sh index b89e36c..cc4db51 100755 --- a/bar-functions/dwm_countdown.sh +++ b/bar-functions/dwm_countdown.sh @@ -9,11 +9,13 @@ dwm_countdown () { for f in /tmp/countdown.*; do if [ -e "$f" ]; then + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "ā³ %s\n" "$(tail -1 /tmp/countdown.*)" + printf "ā³ %s" "$(tail -1 /tmp/countdown.*)" else - printf "CDN %s\n" "$(tail -1 /tmp/countdown.*)" + printf "CDN %s" "$(tail -1 /tmp/countdown.*)" fi + printf "%s\n" "$SEP2" break fi diff --git a/bar-functions/dwm_date.sh b/bar-functions/dwm_date.sh index 43a4a96..654def1 100755 --- a/bar-functions/dwm_date.sh +++ b/bar-functions/dwm_date.sh @@ -6,11 +6,13 @@ # Date is formatted like like this: "[Mon 01-01-00 00:00:00]" dwm_date () { + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "šŸ“† %s\n" "$(date "+%a %d-%m-%y %T")" + printf "šŸ“† %s" "$(date "+%a %d-%m-%y %T")" else - printf "DAT %s\n" "$(date "+%a %d-%m-%y %T")" + printf "DAT %s" "$(date "+%a %d-%m-%y %T")" fi + printf "%s\n" "$SEP2" } dwm_date diff --git a/bar-functions/dwm_keyboard.sh b/bar-functions/dwm_keyboard.sh index 38f514c..a9ae912 100755 --- a/bar-functions/dwm_keyboard.sh +++ b/bar-functions/dwm_keyboard.sh @@ -7,11 +7,13 @@ # Dependencies: xorg-setxkbmap dwm_keyboard () { + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "āŒØ %s\n" "$(setxkbmap -query | awk '/layout/{print $2}')" + printf "āŒØ %s" "$(setxkbmap -query | awk '/layout/{print $2}')" else - printf "KEY %s\n" "$(setxkbmap -query | awk '/layout/{print $2}')" + printf "KEY %s" "$(setxkbmap -query | awk '/layout/{print $2}')" fi + printf "%s\n" "$SEP2" } dwm_keyboard diff --git a/bar-functions/dwm_mail.sh b/bar-functions/dwm_mail.sh index 19478a0..27f3d51 100755 --- a/bar-functions/dwm_mail.sh +++ b/bar-functions/dwm_mail.sh @@ -9,15 +9,17 @@ dwm_mail () { MAILBOX=$(ls /path/to/inbox | wc -l) + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then if [ "$MAILBOX" -eq 0 ]; then - printf "šŸ“Ŗ %s\n" "$MAILBOX" + printf "šŸ“Ŗ %s" "$MAILBOX" else - printf "šŸ“« %s\n" "$MAILBOX" + printf "šŸ“« %s" "$MAILBOX" fi else - printf "MAI %s\n" "$MAILBOX" + printf "MAI %s" "$MAILBOX" fi + printf "%s\n" "$SEP2" } dwm_mail diff --git a/bar-functions/dwm_network.sh b/bar-functions/dwm_network.sh index 8d6e6fb..9398bbb 100755 --- a/bar-functions/dwm_network.sh +++ b/bar-functions/dwm_network.sh @@ -15,11 +15,13 @@ dwm_network () { PRIVATE=$(nmcli -a | grep 'inet4 192' | awk '{print $2}') PUBLIC=$(curl -s https://ipinfo.io/ip) + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "šŸŒ %s %s | %s\n" "$CONNAME" "$PRIVATE" "$PUBLIC" + printf "šŸŒ %s %s | %s" "$CONNAME" "$PRIVATE" "$PUBLIC" else - printf "NET %s %s | %s\n" "$CONNAME" "$PRIVATE" "$PUBLIC" + printf "NET %s %s | %s" "$CONNAME" "$PRIVATE" "$PUBLIC" fi + printf "%s\n" "$SEP2" } dwm_network diff --git a/bar-functions/dwm_pulse.sh b/bar-functions/dwm_pulse.sh index f137436..e4e9149 100755 --- a/bar-functions/dwm_pulse.sh +++ b/bar-functions/dwm_pulse.sh @@ -8,27 +8,30 @@ dwm_pulse () { VOL=$(pamixer --get-volume-human | tr -d '%') + + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then if [ "$VOL" = "muted" ] || [ "$VOL" -eq 0 ]; then - printf "šŸ”‡\n" + printf "šŸ”‡" elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then - printf "šŸ”ˆ %s%%\n" "$VOL" + printf "šŸ”ˆ %s%%" "$VOL" elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then - printf "šŸ”‰ %s%%\n" "$VOL" + printf "šŸ”‰ %s%%" "$VOL" else - printf "šŸ”Š %s%%\n" "$VOL" + printf "šŸ”Š %s%%" "$VOL" fi else if [ "$VOL" = "muted" ] || [ "$VOL" -eq 0 ]; then - printf "MUTE\n" + printf "MUTE" elif [ "$VOL" -gt 0 ] && [ "$VOL" -le 33 ]; then - printf "VOL %s%%\n" "$VOL" + printf "VOL %s%%" "$VOL" elif [ "$VOL" -gt 33 ] && [ "$VOL" -le 66 ]; then - printf "VOL %s%%\n" "$VOL" + printf "VOL %s%%" "$VOL" else - printf "VOL %s%%\n" "$VOL" + printf "VOL %s%%" "$VOL" fi fi + printf "%s\n" "$SEP2" } dwm_pulse diff --git a/bar-functions/dwm_resources.sh b/bar-functions/dwm_resources.sh index 2213316..ca064c2 100755 --- a/bar-functions/dwm_resources.sh +++ b/bar-functions/dwm_resources.sh @@ -15,11 +15,13 @@ dwm_resources () { STOTOT=$(df -h | grep '/home$' | awk '{print $2}') STOPER=$(df -h | grep '/home$' | awk '{print $5}') + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "šŸ’» MEM %s/%s CPU %s STO %s/%s: %s\n" "$MEMUSED" "$MEMTOT" "$CPU" "$STOUSED" "$STOTOT" "$STOPER" + printf "šŸ’» MEM %s/%s CPU %s STO %s/%s: %s" "$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" + printf "STA | MEM %s/%s CPU %s STO %s/%s: %s" "$MEMUSED" "$MEMTOT" "$CPU" "$STOUSED" "$STOTOT" "$STOPER" fi + printf "%s\n" "$SEP2" } dwm_resources diff --git a/bar-functions/dwm_transmission.sh b/bar-functions/dwm_transmission.sh index 5a990c2..f11c719 100755 --- a/bar-functions/dwm_transmission.sh +++ b/bar-functions/dwm_transmission.sh @@ -17,31 +17,33 @@ dwm_transmission () { DOWN=$(printf "%s" "$TORRENT" | awk '{print $5;}') if [ "$ID" != "Sum:" ]; then + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then case "$STATUS" in "Idle") - printf "šŸ›‘ %s | %s %s ā¬†%s ā¬‡%s\n" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" + printf "šŸ›‘ %s | %s %s ā¬†%s ā¬‡%s" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" ;; "Seeding") - printf "šŸŒ± %s | ā¬†%s ā¬‡%s\n" "$NAME" "$UP" "$DOWN" + printf "šŸŒ± %s | ā¬†%s ā¬‡%s" "$NAME" "$UP" "$DOWN" ;; "Downloading") - printf "ā¬ %s | %s %s ā¬†%s ā¬‡%s\n" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" + printf "ā¬ %s | %s %s ā¬†%s ā¬‡%s" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" ;; esac else case "$STATUS" in "Idle") - printf "IDLE %s | %s %s ā¬†%s ā¬‡%s\n" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" + printf "IDLE %s | %s %s ā¬†%s ā¬‡%s" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" ;; "Seeding") - printf "SEEDING %s | ā¬†%s ā¬‡%s\n" "$NAME" "$UP" "$DOWN" + printf "SEEDING %s | ā¬†%s ā¬‡%s" "$NAME" "$UP" "$DOWN" ;; "Downloading") - printf "DOWNLOADING %s | %s %s ā¬†%s ā¬‡%s\n" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" + printf "DOWNLOADING %s | %s %s ā¬†%s ā¬‡%s" "$NAME" "$DONE" "$ETA" "$UP" "$DOWN" ;; esac fi + printf "%s\n" "$SEP2" fi } diff --git a/bar-functions/dwm_vpn.sh b/bar-functions/dwm_vpn.sh index 8566d8c..5617bfa 100755 --- a/bar-functions/dwm_vpn.sh +++ b/bar-functions/dwm_vpn.sh @@ -8,14 +8,15 @@ dwm_vpn () { VPN=$(nmcli -a | grep 'VPN connection' | sed -e 's/\( VPN connection\)*$//g') - if [ "$IDENTIFIER" = "unicode" ]; then - if [ "$VPN" != "" ]; then - printf "šŸ”’ %s\n" "$VPN" - fi - else - if [ "$VPN" != "" ]; then - printf "VPN %s\n" "$VPN" + + if [ "$VPN" != "" ]; then + printf "%s" "$SEP1" + if [ "$IDENTIFIER" = "unicode" ]; then + printf "šŸ”’ %s" "$VPN" + else + printf "VPN %s" "$VPN" fi + printf "%s" "$SEP2" fi } diff --git a/bar-functions/dwm_weather.sh b/bar-functions/dwm_weather.sh index 6b82cef..88a9629 100755 --- a/bar-functions/dwm_weather.sh +++ b/bar-functions/dwm_weather.sh @@ -9,11 +9,14 @@ # Change the value of LOCATION to match your city dwm_weather() { LOCATION=city + + printf "%s" "$SEP1" if [ "$IDENTIFIER" = "unicode" ]; then - printf "%s\n" "$(curl -s wttr.in/$LOCATION?format=1)" + printf "%s" "$(curl -s wttr.in/$LOCATION?format=1)" else - printf "WEA %s\n" "$(curl -s wttr.in/$LOCATION?format=1 | grep -o "[0-9].*")" + printf "WEA %s" "$(curl -s wttr.in/$LOCATION?format=1 | grep -o "[0-9].*")" fi + printf "%s" "$SEP2" } dwm_weather diff --git a/dwm_bar.sh b/dwm_bar.sh index ebd0747..a900581 100755 --- a/dwm_bar.sh +++ b/dwm_bar.sh @@ -16,6 +16,9 @@ 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" +# Change the charachter(s) used to seperate modules. If two are used, they will be placed at the start and end. +export SEP1="[" +export SEP2="]" # Import the modules . "$DIR/bar-functions/dwm_countdown.sh" @@ -37,6 +40,6 @@ export IDENTIFIER="unicode" # Update dwm status bar every second while true do - xsetroot -name "[$(dwm_countdown)][$(dwm_transmission)][$(dwm_cmus)][$(dwm_resources)][$(dwm_battery)][$(dwm_mail)][$(dwm_backlight)][$(dwm_alsa)][$(dwm_weather)][$(dwm_vpn)][$(dwm_network)][$(dwm_keyboard)][$(dwm_date)]" + xsetroot -name "$(dwm_countdown)$(dwm_transmission)$(dwm_cmus)$(dwm_resources)$(dwm_battery)$(dwm_mail)$(dwm_backlight)$(dwm_alsa)$(dwm_pulse)$(dwm_weather)$(dwm_vpn)$(dwm_network)$(dwm_keyboard)$(dwm_date)]" sleep 1 done