Skip to content

Instantly share code, notes, and snippets.

@pinealan
Created February 19, 2021 02:22
Show Gist options
  • Save pinealan/fbc0da8562140b39a5604aa2cead73ba to your computer and use it in GitHub Desktop.
Save pinealan/fbc0da8562140b39a5604aa2cead73ba to your computer and use it in GitHub Desktop.
Direnv hook with summary on exported env variables
direnv_hook() {
local previous_exit_status=$?;
# eval "$(direnv export bash)";
eval "$(direnv export bash 2> >( \
awk '
$0 !~ /^direnv: export/
$0 ~ /^direnv: export/ {
plus = gsub("\\+", "");
minus = gsub("-", "");
change = gsub("~", "");
msg = "direnv: export";
if (0 < plus)
msg = msg " " plus "(+)"
if (0 < minus)
msg = msg " " minus "(-)"
if (0 < change)
msg = msg " " change "(~)"
if (0 < plus || 0 < minus || 0 < change)
print msg
}
' 1>&2 \
))";
return $previous_exit_status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment