Created
January 20, 2021 00:04
-
-
Save runiq/c0e284257780b39d98980ebb3104bf33 to your computer and use it in GitHub Desktop.
How I handle envvars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[ -f "$HOME/.profile" ]] && source "$HOME/.profile" | |
[[ $- == *i* && -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[ -f "/etc/bashrc" ]] && source "/etc/bashrc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -a | |
eval "$(systemctl --user show-environment)" | |
set +a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is in ~/.config/fish/conf.d/00-envvars.fish | |
systemctl_show_environment | source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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