diff options
Diffstat (limited to '')
| -rw-r--r-- | modules/by-name/di/direnv/module.nix | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/modules/by-name/di/direnv/module.nix b/modules/by-name/di/direnv/module.nix index ad47a2a7..fc800f35 100644 --- a/modules/by-name/di/direnv/module.nix +++ b/modules/by-name/di/direnv/module.nix @@ -35,6 +35,8 @@ pkgs.landrun ]; }; + + direnvPkg = lib.getExe direnvCfg.package; in { options.soispha.programs.direnv = { enable = lib.mkEnableOption "direnv"; @@ -44,24 +46,27 @@ in { soispha.programs.fish.integrations.direnv = # fish '' - function __direnv_export_eval - ${lib.getExe direnvCfg.package} export fish | source; + set --global SHOULD_SANDBOX_DIRENV + + function _direnv_export_eval + ${direnvPkg} export fish | source end - if test -z "$NO_DIRENV_LOAD" - function _direnv_hook - if test -f ".env" -o -f ".envrc" -o -f ".nenvrc" - # ${lib.getExe landrun-fish} --interactive --command='__direnv_export_eval' - __direnv_export_eval - end - end + function _direnv_hook --on-variable PWD + if not set --query IN_DIRENV_SANDBOX; + and set --query SHOULD_SANDBOX_DIRENV; + and ${direnvPkg} status | grep 'Found RC path' --quiet; + and ${direnvPkg} status | grep 'No .envrc or .env loaded' --quiet - function __direnv_on_prompt --on-event fish_prompt; - _direnv_hook - end + # We found a RC path, but no RC file is loaded. So we can start our shell and + # load it. + ${lib.getExe landrun-fish} --init-command='_direnv_export_eval' - function _direnv_on_preexec --on-event fish_preexec; - _direnv_hook + # After the user exists (via Ctrl+D), they probably want to change the + # directory. + ll + else + _direnv_export_eval end end ''; |
