sb

shitty bar for dwm
git clone git://git.ckyln.com/~cem/sb.git
Log | Files | Refs | README | LICENSE

commit 6f8fdef57717ab0a34eb8061dacde4120714d48a
parent ce819a6e65c50c4146d0d0d7e293f142e42b1f17
Author: Cem Keylan <cem@ckyln.com>
Date:   Sun, 12 Apr 2020 02:47:12 +0300

various style changes

Diffstat:
Mfunc/sb_battery | 19++++++-------------
Mfunc/sb_brightness | 9++++++---
Mfunc/sb_datetime | 4+---
Mfunc/sb_gethostname | 4++--
Mfunc/sb_ipv4 | 6++----
Mfunc/sb_mail | 6+++---
Mfunc/sb_ram | 8+++-----
Mfunc/sb_ssid | 6++----
8 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/func/sb_battery b/func/sb_battery @@ -1,16 +1,9 @@ # Gets the battery state and capacity # prints to stdout - -state() { - state="$(cat "/sys/class/power_supply/$BATTERY/status")" - case $state in Full) printf "=" ;; Discharging) printf "-" ;; - Charging) printf "+" ;; *) printf "?" ;; esac -} - - -capacity() { tr -d '\n' < "/sys/class/power_supply/$BATTERY/capacity"; } - -battery() { - [ -z "$BATTERY" ] && BATTERY="BAT0" - printf "BAT: $(state) $(capacity) $DELIMITER " +battery() { + read -r stat < "/sys/class/power_supply/${BATTERY:=BAT0}/status" + read -r cap < "/sys/class/power_supply/$BATTERY/capacity" + [ "$cap" -lt 25 ] && [ "$COLORBAR" ] && printf '\x04 ' + printf '%s%% [%s] %s ' "$cap" "$stat" "${COLORBAR+$(printf '\x01')}$DELIMITER" } +xsetroot -name "$(battery)" diff --git a/func/sb_brightness b/func/sb_brightness @@ -1,7 +1,10 @@ # Gets brightness level and prints to stdout brightness() { - printf "BRI: " - xbacklight -get 2>/dev/null | cut -d . -f 1 | tr '\n' '%% ' || return 1 - printf " $DELIMITER " + for bl in /sys/class/backlight/* ; do + [ -d "$bl" ] || return 1 + read -r cur < "$bl/brightness" ; read -r max < "$bl/max_brightness" + per="$(( cur * 100 / max ))" + done + printf 'BRI: %s%% %s ' "$per" "$DELIMETER" } diff --git a/func/sb_datetime b/func/sb_datetime @@ -1,7 +1,5 @@ # Gets datetime and prints to stdout datetime() { - [ -z "$DATE" ] && DATE="%a %d %b %Y %H:%M" - command date +"$DATE" | tr '\n' ' ' || return 1 - printf "$DELIMITER " + printf '%s %s ' "$(command date +"${DATE:-%a %d %b %Y %H:%M}")" "$DELIMITER" } diff --git a/func/sb_gethostname b/func/sb_gethostname @@ -1,6 +1,6 @@ # displays hostname gethostname() { - [ -n "$HOST" ] && printf "$HOST $DELIMITER " && return 0 - printf "$(hostname) $DELIMITER " || return 1 + read -r hostname < /proc/sys/kernel/hostname + printf '%s %s ' "$hostname" "$DELIMITER" } diff --git a/func/sb_ipv4 b/func/sb_ipv4 @@ -3,8 +3,6 @@ # requires interface name as the argument. ipv4() { - [ -z "$1" ] && return 1 - IPV4="$(ip a show "$1" 2>/dev/null | grep 'inet ' | cut -d : -f 2 | awk '{print $2}' | cut -d / -f 1)" - [ -z "$IPV4" ] && return 1 - printf "$1: $IPV4 $DELIMITER " + IPV4="$(ip a show "${1:?}" 2>/dev/null | grep 'inet ' | sed 's/^.*inet //;s/\/.*$//')" + [ "$IPV4" ] && printf '%s: %s %s ' "$1" "$IPV4" "$DELIMITER" } diff --git a/func/sb_mail b/func/sb_mail @@ -3,7 +3,7 @@ # $2 Account Name mail() { - [ -z "$1" ] && printf "Maildir is not set\\n" >&2 && return 1 - [ "$(find "$1" | wc -l)" -gt 1 ] && \ - printf "${2-Mail}: $(expr "$(find "$1" | wc -l)" - 1) $DELIMITER " + [ -z "$1" ] && printf "Maildir is not set\\n" >&2 && return 1 + count="$(find "$1" | wc -l)" ; [ "$count" -gt 1 ] && + printf '%s: %s %s ' "${2:-Mail}" "$(( count - 1 ))" "$DELIMETER" } diff --git a/func/sb_ram b/func/sb_ram @@ -1,9 +1,7 @@ # checks ram usage ram() { - USED="$(command free -m | grep Mem: | awk '{print $3}')" - TOTAL="$(command free -m | grep Mem: | awk '{print $2}')" - printf "RAM: " - expr 100 \* "$USED" / "$TOTAL" | tr -d '\n' - printf "%% $DELIMITER " + USED="$(command free -k | grep Mem: | awk '{print $3}')" + TOTAL="$(command free -k | grep Mem: | awk '{print $2}')" + printf 'RAM: %s%% %s ' "$(( 100 * USED / TOTAL ))" "$DELIMITER" } diff --git a/func/sb_ssid b/func/sb_ssid @@ -1,8 +1,6 @@ # reads ssid from iw ssid() { - [ -z "$1" ] && return 1 - SSID="$(iw dev "$1" info | grep ssid | cut -d ' ' -f2- )" - [ -z "$SSID" ] && return 1 - printf "$SSID $DELIMITER " + SSID="$(iw dev "${1:?}" info | grep ssid | cut -d ' ' -f2- )" + [ "$SSID" ] && printf '%s %s ' "$SSID" "$DELIMITER" }