From b4e501fe44ead4b7dede3a69338e804936019b86 Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Sat, 5 Nov 2016 22:16:16 +0100 Subject: [PATCH] New bar --- scripts/.config/scripts/bar2.sh | 167 +++++++++++++++++++++++++++++ scripts/.config/scripts/barhelp.sh | 30 ++++++ 2 files changed, 197 insertions(+) create mode 100755 scripts/.config/scripts/bar2.sh create mode 100755 scripts/.config/scripts/barhelp.sh diff --git a/scripts/.config/scripts/bar2.sh b/scripts/.config/scripts/bar2.sh new file mode 100755 index 0000000..03a74c6 --- /dev/null +++ b/scripts/.config/scripts/bar2.sh @@ -0,0 +1,167 @@ +#!/bin/bash + +cd "$(dirname $0)" + +source barhelp.sh + +FG="^fg(#FFFFFF)" +BG="#1d1d1f" + +LABEL="^fg(AAAAAA)" +BATTERY_GOOD="^fg(#EEEEEE)" +BATTERY_LOW="^fg(#C37561)" +FONT="Liberation Mono-8" +COLOR_SERVICE_RUNNING="^fg(#EEEEEE)" +COLOR_SERVICE_STOPPED="^fg(#666666)" + +ASSET=~/.config/assets +WS_UNFOCUS="^i($ASSET/wsfree.xbm)" +WS_FOCUS="^i($ASSET/ws.xbm)" + + +mybar () { + W=$1 + A=$2 + P=$3 + shift 3 + bar "$W" 25 5 "$A" "$P" -fn "$FONT" -bg "$BG" -e - -ta c $@ +} + +clock() { + while true; do + echo "${LABEL}Time:${FG} $(date '+%a %d %b') | $(date '+%H:%M:%S')" + sleep 1; + done +} + +battery() { + while true; do + level=$(acpi -b | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }') + if [ "$level" -lt 20 ]; then + batlev="${BATTERY_LOW}$level%${FG}" + else + batlev="${BATTERY_GOOD}$level%${FG}" + fi + + if [ -n "$(acpi -a | grep on-line)" ]; then + batcha="Charging" + else + batcha="Discharging" + fi + + echo "${LABEL}Battery:${FG} $batlev, $batcha" + + sleep 30 + done +} + +wifi() { + while true; do + info=$(nmcli -t -f state,device,connection d | awk -F: '{ if($1=="connected" && $2=="wlp3s0") { print $3; exit; } }') + if [ -z "$info" ]; then + info="-" + fi + echo "${LABEL}Wifi:${FG} $info" + sleep 2; + done +} + +workspace() { + bspc subscribe report | while read line; do + NORMIFS=$IFS + IFS=: + set -- ${line#?} + while [ $# -gt 0 ]; do + case $1 in + [OFU]*) + echo -n "$WS_FOCUS" + ;; + [ofu]*) + echo -n "$WS_UNFOCUS" + ;; + esac + shift + done + echo + IFS=$NORMIFS + done +} + +updates() { + get_pac() { checkupdates | wc -l; } + get_aur() { pacaur -Quaq | wc -l; } + get_useless() { pacman -Qtdq | wc -l; } + + while true; do + internet=$(nmcli -t -f state d | grep connected) + if [ -z "$internet" ]; then + if [ -z "$pac" ]; then + pac=? + fi + if [ -z "$aur" ]; then + aur=? + fi + else + pac=$(get_pac) + aur=$(get_aur) + fi + + useless=$(get_useless) + + updates="$pac+$aur-$useless" + + echo "${LABEL}Updates:${FG} ${updates}" + + sleep 1m; + done +} + +music() { + while true; do + if [ -n "$(mpc status | grep -e paused -e playing)" ]; then + while [ -n "$(mpc status | grep -e paused -e playing)" ]; do + info=$(mpc current -f '[%artist%] - [%title%]') + if [ -n "$(mpc status | grep -e paused)" ]; then + info="${info}, Paused" + fi + echo "${LABEL}Music:${FG} ${info}" + + mpc idle 2>&1 1>/dev/null + done | mybar 400 T 0 + fi + mpc idle 2>&1 1>/dev/null + done +} + +service() { + service=$1 + text=$2 + systemctl is-active -q $service + if [ "$?" -eq 0 ]; then + echo -n "${COLOR_SERVICE_RUNNING}$text${FG}" + else + echo -n "${COLOR_SERVICE_STOPPED}$text${FG}" + fi +} + +services() { + while true; do + service zomnet Z + echo "" + sleep 10 + done +} + +workspace | mybar 200 T 50 & + +clock | mybar 250 B 100 & + +battery | mybar 200 B 25 & + +wifi | mybar 140 B 0 & + +music & + +updates | mybar 130 B 75 & + +services | mybar 50 B 50 diff --git a/scripts/.config/scripts/barhelp.sh b/scripts/.config/scripts/barhelp.sh new file mode 100755 index 0000000..6717342 --- /dev/null +++ b/scripts/.config/scripts/barhelp.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +D=$(xrandr | grep LVDS1 | grep -Eo '[0-9]+x[0-9]+') +DW=$(echo $D | cut -dx -f1) +DH=$(echo $D | cut -dx -f2) + +bar() { + W=$1 + H=$2 + PADDING=$3 + ANCHOR=$4 + POS=$5 + shift 5 + + case $ANCHOR in + T) + Y=$PADDING + ;; + B|*) + Y=$(($DH - $PADDING - $H)) + ;; + esac + + [ "$POS" -gt 100 ] && POS=100 + [ "$POS" -lt 0 ] && POS=0 + + X=$(( ($DW - $W - 2 * $PADDING) * $POS / 100 + $PADDING )) + + dzen2 -x "$X" -y "$Y" -w "$W" -h "$H" "$@" -e "onstart=lower" +}