dotfiles

:)
git clone https://git.sr.ht/~ashymad/dotfiles
Log | Files | Refs | Submodules | LICENSE

commit 1898366f4d11909c6fefb3d8edd91c015d2e3291
parent ca117ed8b1d07337a22676644e1418175a560006
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date:   Tue, 16 Jun 2026 23:59:09 +0200

Flesh out withenv a little

Diffstat:
Mscripts/.local/bin/greetd-greet | 4++--
Mscripts/.local/bin/withenv | 38++++++++++++++++++++++++++++++++------
Msway/.config/sway/env | 4+++-
Mzsh/.zshenv | 9++++++---
4 files changed, 43 insertions(+), 12 deletions(-)

diff --git a/scripts/.local/bin/greetd-greet b/scripts/.local/bin/greetd-greet @@ -7,7 +7,7 @@ export _greetd_withenv="$H/.local/bin/withenv" for bin in fbterm_bi fbterm fbv awww tuigreet; do echo -n "Resolving ${bin}" - bin_path="$(env HOME="$H" "${_greetd_withenv}" "$H/.config/sway/env" which $bin 2>/dev/null)" + bin_path="$(env HOME="$H" "${_greetd_withenv}" -f "$H/.config/sway/env" which $bin 2>/dev/null)" [ -z "$bin_path" ] && { echo " [ERR]" exit 1 @@ -19,4 +19,4 @@ done P="$(xargs -a "$H/.cache/awww/$("${_greetd_awww}" --version | cut -d' ' -f2)"/* -0 sh -c 'echo "$3"' 0)" -exec "${_greetd_fbterm_bi}" "$P" -- "${_greetd_tuigreet}" -u "$U" --asterisks -c "${_greetd_withenv} $H/.config/sway/env sway" +exec "${_greetd_fbterm_bi}" "$P" -- "${_greetd_tuigreet}" -u "$U" --asterisks -c "${_greetd_withenv} -f $H/.config/sway/env sway" diff --git a/scripts/.local/bin/withenv b/scripts/.local/bin/withenv @@ -1,18 +1,44 @@ #!/bin/sh +set -e -if [ "$1" = "--export" ]; then - awk '{print "export \"" $0 "\""}' "$2" +ENVFILE="-" + +while :; do + case $1 in + -e|--export) EXPORT=1; shift ;; + -i|--ignore) IGNORE=1; shift ;; + -f|--file) ENVFILE="$2"; shift 2 ;; + --) break ;; + -*) echo "Invalid option $1"; exit 1 ;; + *) break ;; + esac +done + +subst() { + cat "$1" \ + | { tee /dev/fd/3 \ + | sha1sum \ + | awk '{print "SHA1SUM=" $1}'; \ + } 3>&1 \ + | tail -r \ + | xargs sh -c 'printf "%s\n" "${@}" | tail -r | env "$0" envsubst' -- +} + +if [ "$IGNORE" = 1 ]; then + ENVARGS="-i" +fi + +if [ "$EXPORT" = 1 ]; then + subst "$ENVFILE" | sed 's/^\([^=]*\)=\(.*\)$/export \1="\2"/' exit 0 fi -ENVFILE="$1" -shift fifo="$(mktemp -d)/fifo" mkfifo "$fifo" ( - envsubst < "$ENVFILE" | tr '\n' '\0' + subst "$ENVFILE" | tr '\n' '\0' [ "$#" -gt 0 ] && printf "%s\0" "$@" rm -rf "$(dirname "$fifo")" ) >> "$fifo" & -exec xargs -0 -a "$fifo" env +exec xargs -0 -a "$fifo" env $ENVARGS diff --git a/sway/.config/sway/env b/sway/.config/sway/env @@ -2,4 +2,6 @@ XDG_SESSION_TYPE=wayland XDG_DATA_DIRS=$HOME/.usr/local/share:$XDG_DATA_DIRS PATH=$HOME/.local/bin:$HOME/.usr/local/bin:$HOME/.usr/local/sbin:$PATH PYTHONPATH=$HOME/.usr/local/lib/python3.14/site-packages:/usr/lib/python3.14/site-packages -SWAY_ENV=1 +PERL5LIB=$HOME/.usr/local/lib/perl5/ +PKG_CONFIG_PATH=$HOME/.usr/local/lib/pkgconfig/ +SWAY_ENV=$SHA1SUM diff --git a/zsh/.zshenv b/zsh/.zshenv @@ -1,8 +1,12 @@ skip_global_compinit=1 -if [[ $SWAY_ENV != 1 ]]; then - source <(~/.local/bin/withenv --export ~/.config/sway/env) +SWAY_ENV_FILE=~/.config/sway/env +SWAY_ENV_SHA="$(sha1sum "$SWAY_ENV_FILE" | cut -d' ' -f1)" +if [[ $SWAY_ENV != $SWAY_ENV_SHA ]]; then + source <(~/.local/bin/withenv -e -f "$SWAY_ENV_FILE") fi +unset SWAY_ENV_FILE +unset SWAY_ENV_SHA export MISE_Found="$(which mise &>/dev/null; echo $?)" tools=( 'nvim' ) @@ -19,7 +23,6 @@ done [ -n "${tool_paths[nvim]}" ] && export EDITOR="${tool_paths[nvim]}" && export SUDO_EDITOR="$EDITOR" export VIVID_THEME=rose-pine-moon -export PERL5LIB="$HOME/.usr/local/lib/perl5/" [ -f "$XDG_RUNTIME_DIR/arista-ssh/agent.sock" ] && export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/arista-ssh/agent.sock" export ZSH_EXEC=1 export HOST