diff --git a/dk-home/.local/bin/bar b/dk-home/.local/bin/bar index 5bd91fba..cc8dbc6d 100755 --- a/dk-home/.local/bin/bar +++ b/dk-home/.local/bin/bar @@ -12,12 +12,15 @@ underline=3 separator="┃" # xfonts (adjust size based on resolution) -size=$(xrandr | grep ' connected' | grep -o '[0-9]\+x[0-9]\+' | cut -d'x' -f2) -if (( size >= 2160 )); then +px=$(xrandr | grep ' connected' | grep -o '[0-9]\+x[0-9]\+' | cut -d'x' -f2) +mm=$(xrandr | grep ' connected' | grep -o '[0-9]\+mm' | tail -n1 | sed 's/mm//') +dpi=$(( (px / mm) * 25 )) + +if (( dpi >= 140 )); then font0="-xos4-terminus-medium-r-normal--24-240-72-72-c-120-iso10646-1" -elif (( size >= 1440 )); then +elif (( dpi >= 120 )); then font0="-xos4-terminus-medium-r-normal--18-240-72-72-c-120-iso10646-1" -elif (( size >= 1080 )); then +elif (( dpi >= 100 )); then font0="-xos4-terminus-medium-r-normal--14-240-72-72-c-120-iso10646-1" else font0="-xos4-terminus-medium-r-normal--12-240-72-72-c-120-iso10646-1" @@ -90,15 +93,48 @@ volume() fi } +network() +{ + check() + { + if hash nm-online > /dev/null 2>&1 && [[ $(systemctl is-active NetworkManager.service) == "active" ]]; then + nm-online > /dev/null 2>&1 + else + ping -qc1 'archlinux.org' > /dev/null 2>&1 + fi + } + + if [[ $1 ]]; then + until check; do + printf 'N%s\n' "%{A1:$1:} disconnected %{A}" + sleep 5 + done + while :; do + printf 'N%s\n' "%{A1:$1:} connected %{A}" + sleep 100 + done + else + until check; do + printf 'N%s\n' " disconnected %{A}" + sleep 5 + done + while :; do + printf 'N%s\n' " connected %{A}" + sleep 100 + done + fi +} + parsefifo() { - typeset f='' b='' u='' wm='' time='' bat='' vol='' title='' layout='' s="$separator" + typeset f='' b='' u='' wm='' time='' net='' bat='' vol='' title='' layout='' s="$separator" while read -r line; do case $line in T*) time="${line#?}" ;; V*) vol="${line#?}" ;; B*) bat="${line#?}" ;; + N*) net="${line#?}" ;; A*) title="${line#?}" title="${title:0:50}";; L*) l="${line#?}"; layout="${layouts[$l]}" ;; W*) @@ -116,7 +152,7 @@ parsefifo() done ;; esac - printf "%s\n" "%{l}$wm $s $layout%{c}$title%{r}${bat}${s}${vol}${s}${time}" + printf "%s\n" "%{l}$wm $s $layout%{c}$title%{r}${net}${s}${bat}${s}${vol}${s}${time}" done } @@ -132,8 +168,9 @@ mkfifo "$fifo" # here we dump info into the FIFO, order does not matter things are parsed # out using the first character of the line. Click commands for left button # can be added by passing an argument containing the command (like volume below) +network 'xterm -e nmtui-connect' > "$fifo" & clock 'gsimplecal' > "$fifo" & -battery 'xfce4-power-manager-settings' > "$fifo" & +battery '' > "$fifo" & volume 'pavucontrol' > "$fifo" & dkcmd status type=bar > "$fifo" &