From 3033c6646c1d0711846ce8fffa2fa532d4b27622 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Fri, 8 May 2020 16:18:32 +0200 Subject: [PATCH] [util/xrandr] Add binaries for rewriting i3 config --- bin/load-i3-bars.sh | 30 ++++++++++++++++++++++++++++++ bin/toggle-display.sh | 15 +++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 bin/load-i3-bars.sh create mode 100755 bin/toggle-display.sh diff --git a/bin/load-i3-bars.sh b/bin/load-i3-bars.sh new file mode 100755 index 0000000..6292f75 --- /dev/null +++ b/bin/load-i3-bars.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +if [ ! -f ~/.config/i3/config.template ]; then + cp ~/.config/i3/config ~/.config/i3/config.template +else + cp ~/.config/i3/config.template ~/.config/i3/config +fi + +if [ -f ~/.config/i3/config.template.private ]; then + cat ~/.config/i3/config.template.private >> ~/.config/i3/config +fi + +screens=$(xrandr -q|grep ' connected'| grep -P '\d+x\d+' |cut -d' ' -f1) + +echo "screens: $screens" + +while read -r line; do + screen=$(echo $line | cut -d' ' -f1) + others=$(echo $screens|tr ' ' '\n'|grep -v $screen|tr '\n' '-'|sed 's/.$//') + + if [ -f ~/.config/i3/config.$screen-$others ]; then + cat ~/.config/i3/config.$screen-$others >> ~/.config/i3/config + else + if [ -f ~/.config/i3/config.$screen ]; then + cat ~/.config/i3/config.$screen >> ~/.config/i3/config + fi + fi +done <<< "$screens" + +i3-msg restart diff --git a/bin/toggle-display.sh b/bin/toggle-display.sh new file mode 100755 index 0000000..18a0b71 --- /dev/null +++ b/bin/toggle-display.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +echo $(dirname $(readlink -f "$0")) + +i3bar_update=$(dirname $(readlink -f "$0"))/load-i3-bars.sh + +xrandr "$@" + +if [ -f $i3bar_update ]; then + sleep 1 + if [ -f ~/.config/i3/images/background.png ]; then + feh --bg-fill ~/.config/i3/images/background.png + fi + $i3bar_update +fi