Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Cookbook

    • Cookbook
    • Setup
    • Help
    • System
    • Parsing
    • Foreign Shell Scripts
    • Pattern Matching
    • Custom Completers
    • External Completers
    • Module Scenarios
    • Files
    • Git
    • Parsing Git Log
    • Acting on keypresses using `input listen`
    • HTTP
    • Direnv
    • ssh-agent
    • Advanced table workflows
    • Polars vs Pandas vs Nushell
    • jq vs Nushell

Direnv

Many people use direnv to load an environment upon entering a directory as well as unloading it when exiting the directory. Configuring direnv to work with nushell requires nushell version 0.66 or later.


Configuring direnv

To make direnv work with nushell the way it does with other shells, we can use the "hooks" functionality:

$env.config = {
  hooks: {
    pre_prompt: [{ ||
      if (which direnv | is-empty) {
        return
      }

      direnv export json | from json | default {} | load-env
      if 'ENV_CONVERSIONS' in $env and 'PATH' in $env.ENV_CONVERSIONS {
        $env.PATH = do $env.ENV_CONVERSIONS.PATH.from_string $env.PATH
      }
    }]
  }
}

Note

you can follow the nu_scripts of Nushell for the always up-to-date version of the hook above

With that configuration in place, direnv should now work with nushell.

Edit this page on GitHub
Contributors: John Axel Eriksson, Samir Talwar, amtoine, Liam Griffin-Jowett, fdncred, Joaquín Triñanes, Justin Ma, Fawad Halim, Jasha10
Prev
HTTP
Next
ssh-agent