From e9f27213c1cba5e3d2d7961d0092a768727de4dc Mon Sep 17 00:00:00 2001 From: Yuri Zamyatin Date: Mon, 31 Mar 2025 23:50:11 +0000 Subject: [PATCH] migrate to gomplate --- arch-user/config/bemenu/config.sh | 24 -------------- arch-user/config/bemenu/env.sh.tmpl | 24 ++++++++++++++ arch-user/config/profile | 7 ++-- arch-user/config/qutebrowser/config.py | 2 +- arch-user/config/qutebrowser/env.sh.tmpl | 3 ++ arch-user/config/sway/config.tmpl | 2 +- arch-user/config/theme.json | 3 +- arch-user/install.sh | 41 +++++------------------- 8 files changed, 41 insertions(+), 65 deletions(-) delete mode 100644 arch-user/config/bemenu/config.sh create mode 100644 arch-user/config/bemenu/env.sh.tmpl create mode 100644 arch-user/config/qutebrowser/env.sh.tmpl diff --git a/arch-user/config/bemenu/config.sh b/arch-user/config/bemenu/config.sh deleted file mode 100644 index efc763a..0000000 --- a/arch-user/config/bemenu/config.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -export BEMENU_OPTS="\ ---ignorecase \ ---width-factor 0.5 \ ---fn \"$THEME_FONT_MONO $THEME_SIZE_FONT_LARGE_PT\" \ ---list 500 \ ---border 2 \ ---scrollbar autohide \ ---border-radius 4 \ ---bdr #$THEME_COLOR_FG_ACCENT$THEME_OPACITY_MID_HEX \ ---scf #$THEME_COLOR_FG_ACCENT$THEME_OPACITY_MID_HEX \ ---scb #$THEME_COLOR_BG$THEME_OPACITY_HIGH_HEX \ ---nb #$THEME_COLOR_BG$THEME_OPACITY_HIGH_HEX \ ---ab #$THEME_COLOR_BG$THEME_OPACITY_HIGH_HEX \ ---hb #$THEME_COLOR_BG$THEME_OPACITY_HIGH_HEX \ ---fb #$THEME_COLOR_BG$THEME_OPACITY_HIGH_HEX \ ---tb #$THEME_COLOR_BG$THEME_OPACITY_HIGH_HEX \ ---nf #$THEME_COLOR_FG \ ---af #$THEME_COLOR_FG \ ---cf #$THEME_COLOR_FG \ ---hf #$THEME_COLOR_FG_ACCENT \ ---tf #$THEME_COLOR_FG_ACCENT \ ---ff #$THEME_COLOR_FG_ACCENT \ -" diff --git a/arch-user/config/bemenu/env.sh.tmpl b/arch-user/config/bemenu/env.sh.tmpl new file mode 100644 index 0000000..ae83804 --- /dev/null +++ b/arch-user/config/bemenu/env.sh.tmpl @@ -0,0 +1,24 @@ +#!/bin/sh +export BEMENU_OPTS="\ +--ignorecase \ +--width-factor 0.5 \ +--fn \"{{ .theme.font.name_mono }} {{ math.Add .theme.font.size_base_pt .theme.font.size_step_pt }}\" \ +--list 500 \ +--border 2 \ +--scrollbar autohide \ +--border-radius 4 \ +--bdr #{{ .theme.color.fg_accent }}{{ math.Mul .theme.opacity.med 255 | conv.ToInt64 | printf "%02X" }} \ +--scf #{{ .theme.color.fg_accent }}{{ math.Mul .theme.opacity.med 255 | conv.ToInt64 | printf "%02X" }} \ +--scb #{{ .theme.color.bg }}{{ math.Mul .theme.opacity.high 255 | conv.ToInt64 | printf "%02X" }} \ +--nb #{{ .theme.color.bg }}{{ math.Mul .theme.opacity.high 255 | conv.ToInt64 | printf "%02X" }} \ +--ab #{{ .theme.color.bg }}{{ math.Mul .theme.opacity.high 255 | conv.ToInt64 | printf "%02X" }} \ +--hb #{{ .theme.color.bg }}{{ math.Mul .theme.opacity.high 255 | conv.ToInt64 | printf "%02X" }} \ +--fb #{{ .theme.color.bg }}{{ math.Mul .theme.opacity.high 255 | conv.ToInt64 | printf "%02X" }} \ +--tb #{{ .theme.color.bg }}{{ math.Mul .theme.opacity.high 255 | conv.ToInt64 | printf "%02X" }} \ +--nf #{{ .theme.color.fg }} \ +--af #{{ .theme.color.fg }} \ +--cf #{{ .theme.color.fg }} \ +--hf #{{ .theme.color.fg_accent }} \ +--tf #{{ .theme.color.fg_accent }} \ +--ff #{{ .theme.color.fg_accent }} \ +" diff --git a/arch-user/config/profile b/arch-user/config/profile index 5d7a95a..bcec3b9 100644 --- a/arch-user/config/profile +++ b/arch-user/config/profile @@ -2,7 +2,6 @@ export PATH=$PATH:~/.local/bin - -{{ jq "1 config/theme.json\n" }} - -source ~/.config/bemenu/config.sh +for fpath in ~/.config/*/env.sh; do + . "$fpath" +done diff --git a/arch-user/config/qutebrowser/config.py b/arch-user/config/qutebrowser/config.py index e8d3e54..7ecf551 100644 --- a/arch-user/config/qutebrowser/config.py +++ b/arch-user/config/qutebrowser/config.py @@ -11,7 +11,7 @@ for mode in ['normal','insert','hint','passthrough','command','prompt','yesno',' # styles config.set('colors.webpage.preferred_color_scheme','dark') config.set('colors.webpage.darkmode.enabled', True) -config.set('colors.webpage.bg','#'+os.environ['THEME_COLOR_BG']) +config.set('colors.webpage.bg','#'+os.environ['QB_THEME_COLOR_BG']) config.set('fonts.default_family','Roboto') # engines config.set('url.searchengines', { diff --git a/arch-user/config/qutebrowser/env.sh.tmpl b/arch-user/config/qutebrowser/env.sh.tmpl new file mode 100644 index 0000000..5d5c15c --- /dev/null +++ b/arch-user/config/qutebrowser/env.sh.tmpl @@ -0,0 +1,3 @@ +#!/bin/sh + +export QB_THEME_COLOR_BG={{ .theme.color.bg }} diff --git a/arch-user/config/sway/config.tmpl b/arch-user/config/sway/config.tmpl index 73ea8cd..f392e5f 100644 --- a/arch-user/config/sway/config.tmpl +++ b/arch-user/config/sway/config.tmpl @@ -15,7 +15,7 @@ set $bwd apostrophe default_border pixel 1 smart_borders on title_align center -font pango:{{ .theme.font.name_regular }} {{ math.Mul .theme.font.size_base_pt .theme.font.size_smaller_em }} +font pango:{{ .theme.font.name_regular }} {{ math.Sub .theme.font.size_base_pt .theme.font.size_step_pt }} output * bg #{{ .theme.color.bg }} solid_color client.focused #{{ .theme.color.bg_accent_light }} #{{ .theme.color.bg_accent_light }} #{{ .theme.color.fg }} #{{ .theme.color.fg_accent }} #{{ .theme.color.bg_accent_light }} client.focused_tab_title #{{ .theme.color.bg_accent_light }}{{ math.Mul .theme.opacity.med 255 | conv.ToInt64 | printf "%02X" }} #{{ .theme.color.bg_accent_light }}{{ math.Mul .theme.opacity.med 255 | conv.ToInt64 | printf "%02X" }} #{{ .theme.color.fg_dark }} #{{ .theme.color.fg_accent }} #{{ .theme.color.bg_accent_light }} diff --git a/arch-user/config/theme.json b/arch-user/config/theme.json index 3d634bb..8c3c109 100644 --- a/arch-user/config/theme.json +++ b/arch-user/config/theme.json @@ -16,7 +16,6 @@ "name_regular": "Roboto", "name_mono": "Roboto Mono", "size_base_pt": 12, - "size_smaller_em": 0.875, - "size_larger_em": 1.1125 + "size_step_pt": 1.5 } } diff --git a/arch-user/install.sh b/arch-user/install.sh index d63e607..2333361 100644 --- a/arch-user/install.sh +++ b/arch-user/install.sh @@ -12,7 +12,7 @@ umask 002 ####### file structure ######### USER_DIRS=( ##### xdg ##### - ~/.config + ~/.config # bkp=weak ~/.local/bin # bkp=weak ~/.local/share # bkp=weak ~/.local/state @@ -41,43 +41,18 @@ cp -rf bin/* ~/.local/bin ################################ ########### config ############# -source config/theme.sh -VARS=$(printenv | \ - grep -E '^(THEME_.\w+)|(USER)=' | \ - sed -e 's/[= ].*//g' | sed -e 's/^/\$/' | tr '\n' ' ' -) -cp_subst() { - mkdir -p "$(dirname "$2")" - envsubst "$VARS" < "$1" > "$2" -} +gomplate --input-dir config \ + --output-map "$HOME/.config/{{ .in | strings.ReplaceAll \".tmpl\" \"\" }}" \ + --exclude-processing "!*.tmpl" \ + --plugin jq=/bin/jq \ + -c theme=config/theme.json -# xdg -cp -rf config/i3blocks ~/.config -cp -rf config/git ~/.config -cp -rf config/vim ~/.config -cp -rf config/xkb ~/.config -cp -rf config/swayidle ~/.config - -# non-xdg -cp -rf config/bash ~/.config ln -sf ~/.config/bash/bashrc ~/.bashrc - -# templated -cp_subst config/sway/config.tmpl ~/.config/sway/config -cp_subst config/foot/foot.ini.tmpl ~/.config/foot/foot.ini -cp_subst config/mako/config.tmpl ~/.config/mako/config -cp_subst config/qutebrowser/config.py.tmpl ~/.config/qutebrowser/config.py - -# dynamic -cp -rf config/profile.part ~/.profile -# shellcheck disable=SC2129 -echo -e "\n# GENERATED" >> ~/.profile -sed '/^#/d' config/theme.sh >> ~/.profile -sed '/^#/d' config/bemenu/config.sh >> ~/.profile +ln -sf ~/.config/profile ~/.profile ################################ ############# data ############ -cp_subst data/qutebrowser/start.html.tmpl ~/.local/share/qutebrowser/start.html +cp -rf data/* ~/.local/share ############################### swaymsg reload || true