From d6af01cec9ee4c0be9efd7e1edc0474a182a7eb0 Mon Sep 17 00:00:00 2001 From: starr-dusT Date: Sat, 10 Dec 2022 23:04:30 -0800 Subject: [PATCH] update for dynamic workspace and polybar switching --- .chezmoiignore | 2 +- .chezmoiscripts/run_before_00_i3_gen.py.tmpl | 41 +++++++++++++++++++ .gitignore | 3 +- dot_bashrc | 2 +- dot_config/i3/config.tmpl | 28 ++++++------- ..._polybar.sh => executable_polybar.sh.tmpl} | 2 +- dot_config/polybar/{dracula => dracula.tmpl} | 4 +- run_before_hello_world.sh | 3 -- vars/.keep | 1 - 9 files changed, 61 insertions(+), 25 deletions(-) create mode 100755 .chezmoiscripts/run_before_00_i3_gen.py.tmpl rename dot_config/i3/scripts/{executable_polybar.sh => executable_polybar.sh.tmpl} (76%) rename dot_config/polybar/{dracula => dracula.tmpl} (97%) delete mode 100755 run_before_hello_world.sh delete mode 100644 vars/.keep diff --git a/.chezmoiignore b/.chezmoiignore index b24d3959..4b512897 100644 --- a/.chezmoiignore +++ b/.chezmoiignore @@ -3,4 +3,4 @@ readme.md .git provision additional-setup.md -vars +.gen diff --git a/.chezmoiscripts/run_before_00_i3_gen.py.tmpl b/.chezmoiscripts/run_before_00_i3_gen.py.tmpl new file mode 100755 index 00000000..4878e761 --- /dev/null +++ b/.chezmoiscripts/run_before_00_i3_gen.py.tmpl @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import subprocess +import json +import pathlib + +# save needed information in a dictionary +i3_dict = {} + +def pri_sec_monitor(): + # save output of xrandr + output = str(subprocess.check_output("xrandr", shell=True)) + primary = [] + secondary = [] + # Get name of primary and secondary monitor + for row in output.split('\\n'): + if " connected" in row and "primary" in row: + primary.append(row.split(" ")[0]) + if " connected" in row and "primary" not in row: + secondary.append(row.split(" ")[0]) + # If we only have on monitor set primary and secondary + # to the one monitor + if len(primary) == 1 and len(secondary) == 0: + secondary = primary + elif len(primary) == 0 and len(secondary) == 1: + primary = secondary + elif len(primary) != 1 or len(secondary) != 1: + print("Error: i3_gen/pri_sec_monitor") + return "ERROR", "ERROR" + return primary[0], secondary[0] + +# pri_sec_monitor +monitors = pri_sec_monitor() +i3_dict["disp_pri"] = monitors[0] +i3_dict["disp_sec"] = monitors[1] + +# write result to json +p = pathlib.Path('{{ .chezmoi.sourceDir }}/.gen/i3.json') +p.parent.mkdir(parents=True, exist_ok=True) +with open(p, 'w') as f: + json.dump(i3_dict, f, indent=4, sort_keys=True) diff --git a/.gitignore b/.gitignore index 686a110a..51497828 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -vars/* -!vars/.keep +.gen diff --git a/dot_bashrc b/dot_bashrc index 18fbbb02..a54c3cf4 100644 --- a/dot_bashrc +++ b/dot_bashrc @@ -28,5 +28,5 @@ alias n="nnn -d -e -H -r" # Chezmoi alias cmc="chezmoi cd" alias cmd="chezmoi apply --verbose --dry-run" -alias cma="chezmoi apply --verbose" +alias cma="chezmoi apply" diff --git a/dot_config/i3/config.tmpl b/dot_config/i3/config.tmpl index 0ce5d1cf..b3763787 100644 --- a/dot_config/i3/config.tmpl +++ b/dot_config/i3/config.tmpl @@ -1,3 +1,5 @@ +{{- $i3:= include ".gen/i3.json" | mustFromJson -}} + # i3 config file (v4) # TODO: add scratchpads (terminal, password manager, discord, task) @@ -5,19 +7,13 @@ #----- VARIABLES #------------------------------------------------------------------------------- -set $HOME /home/tstarr +set $HOME {{ .chezmoi.homeDir }} -#set $DISP_PRI DP-4 -#set $DISP_SEC HDMI-0 +set $DISP_PRI {{ $i3.disp_pri }} +set $DISP_SEC {{ $i3.disp_sec }} -set $DISP_PRI HDMI-0 -set $DISP_SEC DP-4 - -#set $DISP_PRI HDMI-0 -#set $DISP_SEC HDMI-0 - -set $BOR_WIDTH 2 -set $GAP_INNER 2 +set $BOR_WIDTH 4 +set $GAP_INNER 4 set $mod Mod4 @@ -111,7 +107,7 @@ for_window [class="Steam"] move container to workspace "1:game" #------------------------------------------------------------------------------- # i3 utility commands -bindsym $mod+Ctrl+r restart +bindsym $mod+Ctrl+r exec chezmoi apply && i3-msg restart bindsym $mod+Ctrl+q exit bindsym $mod+Ctrl+h resize shrink width 50 bindsym $mod+Ctrl+j resize shrink height 50 @@ -190,6 +186,8 @@ bindsym $mod+b exec --no-startup-id $HOME/.config/i3/scripts/scratch.sh \ #----- AUTOSTART WITH I3 #------------------------------------------------------------------------------- -exec --no-startup-id $HOME/.config/i3/scripts/xrandr.sh -exec_always --no-startup-id $HOME/.config/i3/scripts/polybar.sh -exec_always --no-startup-id nitrogen --restore +exec --no-startup-id "$HOME/.config/i3/scripts/xrandr.sh && \ + chezmoi apply && \ + i3-msg restart && \ + $HOME/.config/i3/scripts/polybar.sh" +exec_always --no-startup-id nitrogen --restore diff --git a/dot_config/i3/scripts/executable_polybar.sh b/dot_config/i3/scripts/executable_polybar.sh.tmpl similarity index 76% rename from dot_config/i3/scripts/executable_polybar.sh rename to dot_config/i3/scripts/executable_polybar.sh.tmpl index 5c6be181..c9675ac7 100644 --- a/dot_config/i3/scripts/executable_polybar.sh +++ b/dot_config/i3/scripts/executable_polybar.sh.tmpl @@ -7,4 +7,4 @@ killall -q polybar while pgrep -x polybar >/dev/null; do sleep 1; done # Launch polybar -polybar -c ~/.config/polybar/dracula & +polybar -c {{ .chezmoi.homeDir }}/.config/polybar/dracula & diff --git a/dot_config/polybar/dracula b/dot_config/polybar/dracula.tmpl similarity index 97% rename from dot_config/polybar/dracula rename to dot_config/polybar/dracula.tmpl index 478d651f..b82dd7fd 100644 --- a/dot_config/polybar/dracula +++ b/dot_config/polybar/dracula.tmpl @@ -1,5 +1,7 @@ +{{- $i3:= include ".gen/i3.json" | mustFromJson -}} + [bar/fullbar] -monitor = HDMI-0 +monitor = {{ $i3.disp_sec }} include-file = ~/.config/polybar/common background = #bb282a36 diff --git a/run_before_hello_world.sh b/run_before_hello_world.sh deleted file mode 100755 index e5a985e3..00000000 --- a/run_before_hello_world.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# -echo "Hello World!" diff --git a/vars/.keep b/vars/.keep deleted file mode 100644 index 2fa992c0..00000000 --- a/vars/.keep +++ /dev/null @@ -1 +0,0 @@ -keep