From 9db18469c4ffe00a833400f2a80160b3efbfd5d1 Mon Sep 17 00:00:00 2001 From: joestandring Date: Fri, 24 May 2019 20:28:02 +0000 Subject: [PATCH] Added dwm_network and dwm_vpn --- README.md | 22 ++++++++++++--- bar-functions/dwm_alsa.sh | 34 +++++++++++++++++++++++ bar-functions/dwm_cmus.sh | 51 ++++++++++++++++++++++++++++++++++ bar-functions/dwm_countdown.sh | 23 +++++++++++++++ bar-functions/dwm_date.sh | 16 +++++++++++ bar-functions/dwm_keyboard.sh | 17 ++++++++++++ bar-functions/dwm_mail.sh | 23 +++++++++++++++ bar-functions/dwm_network.sh | 21 ++++++++++++++ bar-functions/dwm_pulse.sh | 34 +++++++++++++++++++++++ bar-functions/dwm_resources.sh | 25 +++++++++++++++++ bar-functions/dwm_vpn.sh | 23 +++++++++++++++ bar-functions/dwm_weather.sh | 19 +++++++++++++ dwm_bar.sh | 26 +++++++++-------- 13 files changed, 318 insertions(+), 16 deletions(-) create mode 100755 bar-functions/dwm_alsa.sh create mode 100755 bar-functions/dwm_cmus.sh create mode 100755 bar-functions/dwm_countdown.sh create mode 100755 bar-functions/dwm_date.sh create mode 100755 bar-functions/dwm_keyboard.sh create mode 100755 bar-functions/dwm_mail.sh create mode 100755 bar-functions/dwm_network.sh create mode 100755 bar-functions/dwm_pulse.sh create mode 100755 bar-functions/dwm_resources.sh create mode 100755 bar-functions/dwm_vpn.sh create mode 100755 bar-functions/dwm_weather.sh diff --git a/README.md b/README.md index 8487540..7f5935c 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ A modular statusbar for DWM - [Features](#features) - [Current Functions](#current-functions) - [dwm_alsa](#dwm_alsa) + - [dwm_pulse](#dwm_pulse) - [dwm_countdown](#dwm_countdown) - [dwm_keyboard](#dwm_keyboard) - [dwm_resources](#dwm_resources) @@ -11,6 +12,8 @@ A modular statusbar for DWM - [dwm_date](#dwm_date) - [dwm_mail](#dwm_mail) - [dwm_weather](#dwm_weather) + - [dwm_network](#dwm_network) + - [dwm_vpn](#dwm_vpn) - [Installation](#installation) - [Usage](#usage) - [Customizing](#customizing) @@ -26,18 +29,19 @@ Displays the current master volume of ALSA ``` [🔉 55] ``` +Dependencies: ```alsa-utils``` ### dwm_pulse Displays the current master volume of PulseAudio ``` [🔉 55] ``` -Dependencies: ```alsa-utils``` +Dependencies: ```pamixer``` ### dwm_countdown Displays the status of [countdown](https://github.com/joestandring/countdown) ``` [⏳ 00:10:00] ``` -Dependeincies: ```[countdown](https://github.com/joestandring/countdown)``` +Dependencies: ```[countdown](https://github.com/joestandring/countdown)``` ### dwm_keyboard Displays the current keyboard layout ``` @@ -70,6 +74,18 @@ Displays the current weather provided by [wttr.in](https://wttr.in) ``` [☀ +20°C] ``` +### dwm_network +Displays the current network connection, private IP, and public IP +``` +[🌐 enp7s0: 192.168.0.1/24 | 185.199.109.153] +``` +Dependencies: ```NetworkManager, curl``` +### dwm_vpn +Displays the current VPN connection +``` +[🔒 Sweden - Stockholm] +``` +Dependencies: ```NetworkManager-openvpn``` ## Installation 1. Clone and enter the repository: ``` @@ -123,6 +139,4 @@ Code for some functions was modified from: * [suckless.org](https://dwm.suckless.org/status_monitor/) ## More to come! * 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/bar-functions/dwm_alsa.sh b/bar-functions/dwm_alsa.sh new file mode 100755 index 0000000..5fc8bcb --- /dev/null +++ b/bar-functions/dwm_alsa.sh @@ -0,0 +1,34 @@ +#!/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 [ "$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 + 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/bar-functions/dwm_cmus.sh b/bar-functions/dwm_cmus.sh new file mode 100755 index 0000000..2b8294c --- /dev/null +++ b/bar-functions/dwm_cmus.sh @@ -0,0 +1,51 @@ +#!/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 [ "$IDENTIFIER" = "unicode" ]; then + if [ "$STATUS" = "playing" ]; then + STATUS="▶" + else + STATUS="⏸" + fi + + if [ "$SHUFFLE" = "true" ]; then + SHUFFLE=" 🔀" + else + SHUFFLE="" + fi + else + if [ "$STATUS" = "playing" ]; then + STATUS="PLA" + else + STATUS="PAU" + fi + + if [ "$SHUFFLE" = "true" ]; then + SHUFFLE=" S" + else + SHUFFLE="" + fi + fi + + 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/bar-functions/dwm_countdown.sh b/bar-functions/dwm_countdown.sh new file mode 100755 index 0000000..7ba938e --- /dev/null +++ b/bar-functions/dwm_countdown.sh @@ -0,0 +1,23 @@ +#!/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 () { + 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/bar-functions/dwm_date.sh b/bar-functions/dwm_date.sh new file mode 100755 index 0000000..4550fa2 --- /dev/null +++ b/bar-functions/dwm_date.sh @@ -0,0 +1,16 @@ +#!/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 () { + 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/bar-functions/dwm_keyboard.sh b/bar-functions/dwm_keyboard.sh new file mode 100755 index 0000000..686afb6 --- /dev/null +++ b/bar-functions/dwm_keyboard.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# A dwm_bar function that displays the current keyboard layout +# Joe Standring +# GNU GPLv3 + +# Dependencies: xorg-setxkbmap + +dwm_keyboard () { + 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/bar-functions/dwm_mail.sh b/bar-functions/dwm_mail.sh new file mode 100755 index 0000000..c50ee90 --- /dev/null +++ b/bar-functions/dwm_mail.sh @@ -0,0 +1,23 @@ +#!/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 [ "$IDENTIFIER" = "unicode" ]; then + if [ "$MAILBOX" -eq 0 ]; then + printf "[📪 %s]\n" "$MAILBOX" + else + printf "[📫 %s]\n" "$MAILBOX" + fi + else + printf "[MAI %s]\n" "$MAILBOX" + fi +} + +dwm_mail diff --git a/bar-functions/dwm_network.sh b/bar-functions/dwm_network.sh new file mode 100755 index 0000000..e7d044c --- /dev/null +++ b/bar-functions/dwm_network.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# A dwm_bar function to show the current network connection, private IP, and public IP +# Joe Standring +# GNU GPLv3 + +# Dependencies: NetworkManager, curl + +dwm_network () { + CONNAME=$(nmcli -a | grep 'Wired connection' | awk 'NR==1{print $1}') + PRIVATE=$(nmcli -a | grep 'inet4 192' | awk '{print $2}') + PUBLIC=$(curl -s https://ipinfo.io/ip) + + if [ "$IDENTIFIER" = "unicode" ]; then + printf "[🌐 %s %s | %s]\n" "$CONNAME" "$PRIVATE" "$PUBLIC" + else + printf "[NET %s %s | %s]\n" "$CONNAME" "$PRIVATE" "$PUBLIC" + fi +} + +dwm_network diff --git a/bar-functions/dwm_pulse.sh b/bar-functions/dwm_pulse.sh new file mode 100755 index 0000000..02db615 --- /dev/null +++ b/bar-functions/dwm_pulse.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# A dwm_bar function to show the master volume of PulseAudio +# Joe Standring +# GNU GPLv3 + +# Dependencies: pamixer + +dwm_pulse () { + VOL=$(pamixer --get-volume) + 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 + 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_pulse diff --git a/bar-functions/dwm_resources.sh b/bar-functions/dwm_resources.sh new file mode 100755 index 0000000..87db9bb --- /dev/null +++ b/bar-functions/dwm_resources.sh @@ -0,0 +1,25 @@ +#!/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 $3}') + STOTOT=$(df -h | grep '/home$' | awk '{print $2}') + STOPER=$(df -h | grep '/home$' | awk '{print $5}') + + 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/bar-functions/dwm_vpn.sh b/bar-functions/dwm_vpn.sh new file mode 100755 index 0000000..a2558ad --- /dev/null +++ b/bar-functions/dwm_vpn.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# A dwm_bar function to show VPN connections (if any are active) +# Joe Standring +# GNU GPLv3 + +# Dependencies: NetworkManager-openvpn + +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" + fi + fi +} + + +dwm_vpn diff --git a/bar-functions/dwm_weather.sh b/bar-functions/dwm_weather.sh new file mode 100755 index 0000000..678475d --- /dev/null +++ b/bar-functions/dwm_weather.sh @@ -0,0 +1,19 @@ +#!/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 + 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 diff --git a/dwm_bar.sh b/dwm_bar.sh index e8eeea8..11dbfca 100755 --- a/dwm_bar.sh +++ b/dwm_bar.sh @@ -7,7 +7,7 @@ # Dependencies: xorg-xsetroot # Import functions with "$include /route/to/module" -# It is recommended 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 ./bar-functions and use: . "$DIR/bar-functions/dwm_example.sh" # Store the directory the script is running from LOC=$(readlink -f "$0") @@ -15,22 +15,24 @@ 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" +export IDENTIFIER="unicode" # 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_pulse.sh" -. "$DIR/functions/dwm_weather.sh" -. "$DIR/functions/dwm_keyboard.sh" -. "$DIR/functions/dwm_date.sh" +. "$DIR/bar-functions/dwm_countdown.sh" +. "$DIR/bar-functions/dwm_cmus.sh" +. "$DIR/bar-functions/dwm_resources.sh" +. "$DIR/bar-functions/dwm_mail.sh" +. "$DIR/bar-functions/dwm_alsa.sh" +. "$DIR/bar-functions/dwm_pulse.sh" +. "$DIR/bar-functions/dwm_weather.sh" +. "$DIR/bar-functions/dwm_vpn.sh" +. "$DIR/bar-functions/dwm_network.sh" +. "$DIR/bar-functions/dwm_keyboard.sh" +. "$DIR/bar-functions/dwm_date.sh" # 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)" + xsetroot -name "$(dwm_countdown)$(dwm_cmus)$(dwm_resources)$(dwm_mail)$(dwm_alsa)$(dwm_weather)$(dwm_vpn)$(dwm_network)$(dwm_keyboard)$(dwm_date)" sleep 1 done