dotfiles/home/.config/xmobar/multi_mon.sh

41 lines
1 KiB
Bash
Raw Normal View History

2021-07-15 00:58:43 +00:00
#!/bin/sh
2021-07-14 13:15:53 +00:00
if [ $# -lt 1 ]; then
echo "Invalid amount of arguments passed!"
echo "Required parameter: amount of monitors"
exit
fi
MONITOR_AMOUT="$1"
WIDTH=1920
WORK_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/xmobar"
2021-07-15 00:58:43 +00:00
make_position_line(){
2021-07-14 13:15:53 +00:00
xpos=$(($1 * $WIDTH))
2021-07-16 03:10:11 +00:00
line="position = Static { xpos = $xpos, ypos = 0, width = $WIDTH, height = 24 },"
2021-07-14 13:15:53 +00:00
echo "$line"
}
# Remove all already existing specific xmobar configurations
find $WORK_DIR -regex '\./xmobarrc[0-9]+' -exec rm {} +
2021-07-15 00:58:43 +00:00
xmobarhs_content="$(cat $WORK_DIR/xmobarrc.hs)"
position_line_0="$(make_position_line 0)"
2021-07-14 13:15:53 +00:00
for ((n=0;n<MONITOR_AMOUT;n++)); do
cur_file="$WORK_DIR/xmobarrc$n"
2021-07-15 00:58:43 +00:00
# Replace position line to accomodate for multiple monitors
position_line="$(make_position_line $n)"
contents="${xmobarhs_content/$position_line_0/$position_line}"
2021-07-15 01:42:44 +00:00
# Only use Trayer in the 1st xmobar (on single monitor)
2021-07-15 00:58:43 +00:00
if [ $n -ne 0 ]; then
contents="$(grep -v trayerpad <<< $contents)"
fi
echo "$contents" > "$cur_file"
2021-07-14 13:15:53 +00:00
echo "$cur_file created."
done