.
This commit is contained in:
parent
093a7a7c79
commit
9f0f94846e
4 changed files with 133 additions and 4 deletions
|
|
@ -12,9 +12,7 @@ date > "$logfile"
|
|||
|
||||
# load sxhkd for keybinds
|
||||
pgrep sxhkd || sxhkd -c "$HOME/.config/dk/sxhkdrc" &
|
||||
|
||||
# spawn a scratchpad terminal if not already (see sxhkdrc and rules for binds/setup)
|
||||
# pgrep -f "st -c scratchpad" || st -c scratchpad &
|
||||
pgrep bar.sh || bar.sh &
|
||||
|
||||
# adjust border widths based on the DPI of the monitor
|
||||
px=$(xrandr | grep ' connected' | tail -n1 | grep -o '[0-9]\+x[0-9]\+' | cut -d'x' -f2)
|
||||
|
|
|
|||
Binary file not shown.
131
files/.local/bin/bar.sh
Executable file
131
files/.local/bin/bar.sh
Executable file
|
|
@ -0,0 +1,131 @@
|
|||
#!/bin/bash
|
||||
# shellcheck disable=SC2059,SC2064,SC2086,SC2001,SC2016
|
||||
|
||||
# simple lightweight lemonbar script for use with dk
|
||||
|
||||
set -eE -o pipefail
|
||||
|
||||
bg="#3f3c6d" # background colour
|
||||
fg="#a39ef1" # foreground colour
|
||||
hi="#00aaaa" # highlight colour
|
||||
ul=2 # underline thickness
|
||||
sep="┃" # separator text
|
||||
font="-xos4-terminus-medium-r-normal--12-240-72-72-c-120-iso10646-1"
|
||||
fifo="/tmp/bar.fifo"
|
||||
|
||||
# adjust font size based on resolution DPI
|
||||
px=$(xrandr | grep ' connected' | tail -n1 | grep -o '[0-9]\+x[0-9]\+' | cut -d'x' -f2)
|
||||
mm=$(xrandr | grep ' connected' | tail -n1 | grep -o '[0-9]\+mm' | tail -n1 | sed 's/mm//')
|
||||
dpi=$(( (px / mm) * 25 ))
|
||||
if (( dpi >= 140 )); then
|
||||
font="-xos4-terminus-medium-r-normal--20-240-72-72-c-120-iso10646-1"
|
||||
elif (( dpi >= 120 )); then
|
||||
font="-xos4-terminus-medium-r-normal--16-240-72-72-c-120-iso10646-1"
|
||||
elif (( dpi >= 100 )); then
|
||||
font="-xos4-terminus-medium-r-normal--12-240-72-72-c-120-iso10646-1"
|
||||
fi
|
||||
|
||||
clock()
|
||||
{
|
||||
date +"T %a %H:%M $sep"
|
||||
|
||||
# sync up the clock to the minute mark
|
||||
min=$(date +"%M")
|
||||
while [[ $(date +"%M") == "$min" ]]; do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
while :; do
|
||||
date +"T %a %H:%M $sep"
|
||||
sleep 60
|
||||
done
|
||||
}
|
||||
|
||||
battery()
|
||||
{
|
||||
while :; do
|
||||
perc="$(cat /sys/class/power_supply/BAT0/capacity)"
|
||||
printf 'B Bat: %s%%%s\n' " ${perc}"
|
||||
sleep 60
|
||||
done
|
||||
}
|
||||
|
||||
volume()
|
||||
{
|
||||
vol="$(amixer sget Master | awk -F"[][]" '/(Mono|Left):/ { print $2 }')"
|
||||
printf 'V vol: %s%%\n' "$vol"
|
||||
}
|
||||
|
||||
workspaces()
|
||||
{
|
||||
# these will be filled out once we eval each line
|
||||
typeset name="" title="" layout="" focused=false active=false
|
||||
|
||||
WS=""
|
||||
while read -r l; do
|
||||
eval "$l"
|
||||
if [[ $l =~ ^title=* ]]; then
|
||||
# default foreground, background, and underline colours
|
||||
# changing the foreground and underline based on
|
||||
# the active and focused state
|
||||
f="$fg" b="$bg" u="$fg";
|
||||
$active && u="$hi"
|
||||
if $focused; then
|
||||
# clicking the layout symbol will cycle the layout
|
||||
lyt="%{A:dkcmd set layout cycle:}${layouts[$layout]}%{A}"
|
||||
WIN="${title:0:50}"
|
||||
f="$hi"
|
||||
fi
|
||||
# clicking on a workspace name will view it
|
||||
WS="$WS%{F$f}%{B$b}%{+u}%{U$u}%{A:dkcmd ws $name:} $name %{A}%{-u}%{B-}%{F-}"
|
||||
fi
|
||||
# turn the dk JSON output into lines that can be `eval`ed one by one,
|
||||
# filling out the following fields: name, focused, active, layout, title
|
||||
done < <(dkcmd -p <<< "$1" | sed '/.*\[\|]/d; /[{}],\?/d; s/^\s*\|,$//g; /"monitor":\|"number":\|"id":/d; s/"\(.*\)": /\1=/; s/\$(/\\\$(/g; s/`/\\`/g')
|
||||
WS="$WS $sep $lyt"
|
||||
}
|
||||
|
||||
parsefifo()
|
||||
{
|
||||
# globals to simplify the workspaces call
|
||||
declare -g WS WIN
|
||||
|
||||
local time vol bat net
|
||||
|
||||
while read -r line; do
|
||||
case $line in
|
||||
T*) time="${line#?}" ;;
|
||||
V*) vol="${line#?}" ;;
|
||||
B*) bat="${line#?}" ;;
|
||||
N*) net="${line#?}" ;;
|
||||
'{'*) workspaces "$line" ;;
|
||||
esac
|
||||
printf "%s\n" "%{l}$sep ${WS}%{c}${WIN}%{r}${net}${bat}${vol}${time}"
|
||||
done
|
||||
}
|
||||
|
||||
# kill the process and cleanup if we exit or get killed
|
||||
trap "trap - TERM; rm -f '$fifo'; kill 0" INT TERM QUIT EXIT PIPE
|
||||
|
||||
# make the fifo
|
||||
[ -e "$fifo" ] && rm "$fifo"
|
||||
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 below)
|
||||
#
|
||||
# comment a line to remove the "module"
|
||||
clock > "$fifo" &
|
||||
battery > "$fifo" &
|
||||
volume > "$fifo" &
|
||||
dkcmd status type=bar > "$fifo" &
|
||||
|
||||
# run the pipeline
|
||||
if [[ $1 == '-b' ]]; then
|
||||
parsefifo < "$fifo" | lemonbar -b -a 32 -u $ul -B "$bg" -F "$fg" -f "$font" | sh;
|
||||
else
|
||||
parsefifo < "$fifo" | lemonbar -a 32 -u $ul -B "$bg" -F "$fg" -f "$font" | sh
|
||||
fi
|
||||
|
||||
# vim:ft=sh:fdm=marker:fmr={,}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
fontname=Iosevka 12
|
||||
selchars=-A-Za-z0-9,./?%&#:_
|
||||
scrollback=1000
|
||||
bgcolor=rgb(246,245,244)
|
||||
bgcolor=rgb(255,255,255)
|
||||
fgcolor=rgb(0,0,0)
|
||||
palette_color_0=rgb(0,0,0)
|
||||
palette_color_1=rgb(170,0,0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue