From ef6d56b2a8960bd2a9171c717d5520e89dee148b Mon Sep 17 00:00:00 2001 From: Tobias Schmidl <5060861-schtobia@users.noreply.gitlab.com> Date: Tue, 24 Jan 2023 15:33:08 +0100 Subject: [PATCH] moved the generation of local environment variables to its own generator script --- .local/bin/autostart.example | 3 +-- .local/bin/generate-env | 21 +++++++++++++++++++++ .xsessionrc | 9 +-------- .zshrc | 9 ++------- 4 files changed, 25 insertions(+), 17 deletions(-) create mode 100755 .local/bin/generate-env diff --git a/.local/bin/autostart.example b/.local/bin/autostart.example index fb805e4..e008b6c 100755 --- a/.local/bin/autostart.example +++ b/.local/bin/autostart.example @@ -1,5 +1,4 @@ #! /bin/sh -[ -r $HOME/.fehbg ] && . $HOME/.fehbg start-pulseaudio-x11 compton -b -echo "Started on `date -Iseconds`" > $HOME/log +[ -r "$HOME"/.fehbg ] && . "$HOME"/.fehbg diff --git a/.local/bin/generate-env b/.local/bin/generate-env new file mode 100755 index 0000000..313155c --- /dev/null +++ b/.local/bin/generate-env @@ -0,0 +1,21 @@ +#! /bin/sh +if [ -d /usr/lib/systemd/system-environment-generators ]; +then + run-parts /usr/lib/systemd/user-environment-generators +else + cat "$HOME"/.config/environment.d/* +fi | grep -v '#' | grep -v '^[[:space:]]*$' | while read -r cur_env; do export "${cur_env?}"; done + +command -v ip >/dev/null 2>&1 && +{ + LOCAL_IP="$(ip route | sed -En '/.*linkdown/! s/.*src\s+([^ ]+)\s*/\1/p')" + + export LOCAL_IP + TARGET_FILE="$(readlink -f "${XDG_RUNTIME_DIR:-${TMPDIR:-$HOME}}")/local_ip" + [ ! -r "$TARGET_FILE" ] && echo "$LOCAL_IP" > "$TARGET_FILE" +} + +# Make sure we include this part only once +[ -n "$USER_ENVIRONMENT_GENERATORS" ] && return +export USER_ENVIRONMENT_GENERATORS=1 +PATH="$HOME/.local/bin:$PATH" diff --git a/.xsessionrc b/.xsessionrc index 63ba495..64a2c2b 100644 --- a/.xsessionrc +++ b/.xsessionrc @@ -1,8 +1 @@ -# Make sure we include this file only once -if [ -z $LOCAL_BIN_ALREADY_SET ]; -then - export LOCAL_BIN_ALREADY_SET=1 - # set PATH so it includes user's private bin if it exists - [ -d "$HOME/.local/bin" ] && PATH="$HOME/.local/bin:$PATH" - [ -d "$HOME/bin" ] && PATH="$HOME/bin:$PATH" -fi +. $HOME/.local/bin/generate-env diff --git a/.zshrc b/.zshrc index 80b6bdb..b7297d3 100644 --- a/.zshrc +++ b/.zshrc @@ -1,10 +1,3 @@ -if [ -d /usr/lib/systemd/system-environment-generators ]; -then - run-parts /usr/lib/systemd/user-environment-generators | grep -v '#' | grep -v '^ $' | while read cur_env; do export ${cur_env}; done -else - cat $HOME/.config/environment.d/* | grep -v '#' | grep -v '^$' | while read cur_env; do export "${cur_env}"; done -fi - setopt HIST_EXPIRE_DUPS_FIRST setopt HIST_IGNORE_DUPS setopt HIST_IGNORE_ALL_DUPS @@ -41,6 +34,8 @@ EOBUNDLES antigen theme gallifrey antigen apply +source "$HOME/.local/bin/generate-env" + hash direnv &> /dev/null && eval "$(direnv hook zsh)" chpwd() { exa } ZSH_AUTOSUGGEST_STRATEGY=match_prev_cmd