Skip to content

Instantly share code, notes, and snippets.

@runiq
Created January 20, 2021 00:04
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runiq/c0e284257780b39d98980ebb3104bf33 to your computer and use it in GitHub Desktop.
Save runiq/c0e284257780b39d98980ebb3104bf33 to your computer and use it in GitHub Desktop.
How I handle envvars
[[ -f "$HOME/.profile" ]] && source "$HOME/.profile"
[[ $- == *i* && -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"
[[ -f "/etc/bashrc" ]] && source "/etc/bashrc"
set -a
eval "$(systemctl --user show-environment)"
set +a
#!/usr/bin/env sh
# This is in ~/.config/plasma-workspace/env/00-envvars.sh
# Exports all variables in ~/.config/environment.d/*.conf
set -a
eval "$(systemctl --user show-environment)"
set +a
# This is in ~/.config/fish/conf.d/00-envvars.fish
systemctl_show_environment | source
# This is in ~/.config/fish/functions/systemctl_show_environment.fish
function systemctl_show_environment -d "Formats output of `systemctl --user show-environment` for sourcing from fish"
systemctl --user show-environment \
| sed \
# Skip read-only variables
-e '/^_=/d; /^PWD=/d; /^SHLVL=/d' \
# Add `set -x ` to the beginning of the line
-e '/^XDG_\(DATA\|CONFIG\)_DIRS/ ! s/^/set -x /' \
# Add `set --path -x ` to the beginning of the line for XDG_(DATA|CONFIG)_DIRS
-e '/^XDG_\(DATA\|CONFIG\)_DIRS/ s/^/set --path -x /' \
# Replace first = with a space
-e 's/=\(.*\)/ "\1"/' \
# Turn `$'(...)'` into `(...)`
-e 's/"\$\(\'.*\'\)"$/\1/' \
# Turn `:` to ` `, but not in DBUS_SESSION_BUS_ADDRESS or DISPLAY or SKIM_DEFAULT_OPTIONS
-e '/\(DBUS_SESSION_BUS_ADDRESS\|DISPLAY\|SKIM_DEFAULT_OPTIONS\)/ ! s/:/" "/g'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment