From ccba451d3d1449a6405d549f9c728668fa0bdd71 Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Wed, 9 Feb 2022 17:54:04 +0100 Subject: [PATCH] [X11] Preprocess ./.Xresources when installing --- .install.conf.yaml | 10 +++++-- X11/{Xresources => Xresources.src} | 0 bin/Xresources-preprocess | 45 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) rename X11/{Xresources => Xresources.src} (100%) create mode 100755 bin/Xresources-preprocess diff --git a/.install.conf.yaml b/.install.conf.yaml index 4c7ff40..c74cf68 100644 --- a/.install.conf.yaml +++ b/.install.conf.yaml @@ -27,7 +27,7 @@ ~/.vimrc: vim/vimrc ~/.xinitrc: X11/xinitrc ~/.xprofile: X11/xprofile - ~/.Xresources: X11/Xresources + ~/.Xresources.src: X11/Xresources.src ~/.Xresources.d/urxvt: urxvt/Xresources ~/.config/user-dirs.dirs: X11/user-dirs.dirs ~/.config/awesome: awesome @@ -37,5 +37,9 @@ ~/.ssh/keys/: mode: 0700 -#- shell: -# - git submodules update # after linking ~/.gitconfig +- shell: + - + command: ./bin/Xresources-preprocess + description: Preprocess Xresources.src so that xrdb doesn't have to. + stderr: true +# - git submodules update # after linking ~/.gitconfig diff --git a/X11/Xresources b/X11/Xresources.src similarity index 100% rename from X11/Xresources rename to X11/Xresources.src diff --git a/bin/Xresources-preprocess b/bin/Xresources-preprocess new file mode 100755 index 0000000..d44c3ad --- /dev/null +++ b/bin/Xresources-preprocess @@ -0,0 +1,45 @@ +#!/bin/sh + +# Use the precompiler to allow for `xrdb -nocpp -merge ~/.Xresources`. +# Inspiration from https://github.com/dolmen/Xresources.edit/blob/1be4f5601b3d4e8befa043386288c64e724ed746/Xresources.edit + +fname=.Xresources +ext=src +force= + +# Initial setup: move $fname to $fname.$ext +if [ ! -f "$HOME/$fname.$ext" ]; then + cat "$HOME/$fname" > "$HOME/$fname.$ext" + + # Make $fname non-writable to discourage direct editing + chmod a-wx "$HOME/$fname" +fi + +# Check mtime +if [ -f "$HOME/$fname" -a "$HOME/$fname" -nt "$HOME/$fname.$ext" ]; then + { + echo "~/$fname is more recent than ~/$fname.$ext" + echo "You have to fix this manually." + echo "e.g. touch ~/$fname.$ext" + } >&2 + exit 1 +fi + + +# Run cpp and save the result as ~/$fname +[ -e "$HOME/$fname" ] && chmod u+w "$HOME/$fname" + +{ + echo '! *************************************************' + echo "! Do not edit ~/$fname, but ~/$fname.$ext" + echo '! *************************************************' + echo '! vim:set ft=xdefaults:' + echo '!' +} > "$HOME/$fname" + +cpp "$HOME/$fname.$ext" | tee -a "$HOME/$fname" +res=$? + +# Make $fname non-writable to discourage direct editing +chmod a-wx "$HOME/$fname" +exit $res