Dynamically resize xmobar for trayer

This commit is contained in:
ItsDrike 2021-07-15 02:58:43 +02:00
parent d83382e570
commit a88bea6ba2
No known key found for this signature in database
GPG key ID: B5F6B41F708C3ADD
6 changed files with 91 additions and 13 deletions

View file

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
if [ $# -lt 1 ]; then
echo "Invalid amount of arguments passed!"
@ -10,7 +10,7 @@ MONITOR_AMOUT="$1"
WIDTH=1920
WORK_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/xmobar"
make_line(){
make_position_line(){
xpos=$(($1 * $WIDTH))
line=", position = Static { xpos = $xpos, ypos = 0, width = $WIDTH, height = 24 }"
echo "$line"
@ -20,8 +20,22 @@ make_line(){
# Remove all already existing specific xmobar configurations
find $WORK_DIR -regex '\./xmobarrc[0-9]+' -exec rm {} +
xmobarhs_content="$(cat $WORK_DIR/xmobarrc.hs)"
position_line_0="$(make_position_line 0)"
for ((n=0;n<MONITOR_AMOUT;n++)); do
cur_file="$WORK_DIR/xmobarrc$n"
sed "s/$(make_line 0)/$(make_line $n)/g" "$WORK_DIR/xmobarrc.hs" > "$cur_file"
# Replace position line to accomodate for multiple monitors
position_line="$(make_position_line $n)"
contents="${xmobarhs_content/$position_line_0/$position_line}"
# Only keep trayer spacer in 1st xmobar
if [ $n -ne 0 ]; then
#contents="${contents/'%trayerpad%'/''}"
contents="$(grep -v trayerpad <<< $contents)"
fi
echo "$contents" > "$cur_file"
echo "$cur_file created."
done