From 6c8022eb972196379d8e48079e618348c9fff238 Mon Sep 17 00:00:00 2001 From: Wryn Wagner Date: Thu, 23 Sep 2021 11:07:12 -0600 Subject: [PATCH] added i3-local configuration updater --- bin/i3/update-local-config | 59 ++++++++++++++++++++++++++++++++++++++ env/env.zsh | 4 +++ 2 files changed, 63 insertions(+) create mode 100755 bin/i3/update-local-config diff --git a/bin/i3/update-local-config b/bin/i3/update-local-config new file mode 100755 index 0000000..0d9af48 --- /dev/null +++ b/bin/i3/update-local-config @@ -0,0 +1,59 @@ +#!/bin/zsh +source "$HOME/.config/wryn/env/env.zsh" +source $ZSH_COLOR_UTIL + +##################################################################### + +GLOBAL_FONT_SIZE="$1" +DMENU_FONT_SIZE="$2" +BORDER_PIXEL_SIZE="$3" + +[ ! $GLOBAL_FONT_SIZE ] && GLOBAL_FONT_SIZE=$I3__GLOBAL_FONT_SIZE +[ ! $DMENU_FONT_SIZE ] && DMENU_FONT_SIZE=$I3__DMENU_FONT_SIZE +[ ! $BORDER_PIXEL_SIZE ] && BORDER_PIXEL_SIZE=$I3__BORDER_PIXEL_SIZE + + +LOCAL_CONFIG="$HOME/.config/i3/config" +MODEL_CONFIG="$DOTWRYN/config/i3/config" + +REGEX_FONT='^\(font [^0-9]*\)\(.*\)' +REGEX_DMENU="^\\(.*dmenu_run -fn '[^0-9]*\\)\\([0-9]*\\)'" +REGEX_BORDER='^\(for_window.*border pixel \)\(.*\)' + +DEFAULT_GLOBAL_FONT_SIZE=$(sed -n "s/$REGEX_FONT/\\2/p" $MODEL_CONFIG) +DEFAULT_DMENU_FONT_SIZE=$(sed -n "s/$REGEX_DMENU/\\2/p" $MODEL_CONFIG) +DEFAULT_BORDER_PIXEL_SIZE=$(sed -n "s/$REGEX_BORDER/\\2/p" $MODEL_CONFIG) + +##################################################################### + +RESET_CONFIG_TO_DEFAULT() { + STATUS 'relinking config to .wryn/config/i3/config' + ln -s $MODEL_CONFIG $LOCAL_CONFIG +} + +UPDATE_CONFIG() { + [ ! $GLOBAL_FONT_SIZE ] && GLOBAL_FONT_SIZE=$DEFAULT_GLOBAL_FONT_SIZE + [ ! $DMENU_FONT_SIZE ] && DMENU_FONT_SIZE=$DEFAULT_DMENU_FONT_SIZE + [ ! $BORDER_PIXEL_SIZE ] && BORDER_PIXEL_SIZE=$DEFAULT_BORDER_PIXEL_SIZE + + STATUS 'updating config with the following settings:' + MENU "GLOBAL_FONT_SIZE : $GLOBAL_FONT_SIZE" + MENU "DMENU_FONT_SIZE : $DMENU_FONT_SIZE" + MENU "BORDER_PIXEL_SIZE : $BORDER_PIXEL_SIZE" + + sed "\ +s/$REGEX_FONT/\\1$GLOBAL_FONT_SIZE/;\ +s/$REGEX_DMENU/\\1$DMENU_FONT_SIZE'/;\ +s/$REGEX_BORDER/\\1$BORDER_PIXEL_SIZE/;\ +" $MODEL_CONFIG > $LOCAL_CONFIG +} + +##################################################################### + +[ -f $LOCAL_CONFIG ] && rm $LOCAL_CONFIG +[ ! $GLOBAL_FONT_SIZE ] && [ ! $DMENU_FONT_SIZE ] && [ ! $BORDER_PIXEL_SIZE ] \ + && RESET_CONFIG_TO_DEFAULT 2>/dev/null \ + || UPDATE_CONFIG 2>/dev/null \ + ; + +return 0 diff --git a/env/env.zsh b/env/env.zsh index 66d566f..df1db53 100644 --- a/env/env.zsh +++ b/env/env.zsh @@ -19,6 +19,10 @@ RIPGREP_CONFIG_PATH="$HOME/.config/ripgrep/config" TMUX_DEFAULT_SESSION_NAME='wryn' WEBBROWSER='google-chrome-stable' +#I3__GLOBAL_FONT_SIZE= +#I3__DMENU_FONT_SIZE= +#I3__BORDER_PIXEL_SIZE= + PS1_BRANCH_SYMBOL='' PS1_INDICATOR_SYMBOL='☕' PS1_SEPARATOR='::'