### Install direnv using Bash script Source: https://direnv.net/docs/installation.html Use this command to download and run the direnv installation script. This is a quick way to get the latest binary build. ```bash curl -sfL https://direnv.net/install.sh | bash ``` -------------------------------- ### Basic direnv Usage in GitHub Actions Source: https://direnv.net/docs/github-actions.html This example demonstrates a basic GitHub Actions workflow that installs direnv, loads environment variables from .envrc, and runs tests. ```yaml name: CI on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install direnv run: | curl -sfL https://direnv.net/install.sh | bash echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Load environment variables run: | direnv allow . direnv export gha > "$GITHUB_ENV" - name: Run tests run: | # Your environment variables from .envrc are now available echo "DATABASE_URL=$DATABASE_URL" make test ``` -------------------------------- ### Install direnv using install script Source: https://direnv.net/docs/github-actions.html Recommended method for installing direnv in GitHub Actions using a curl script. ```yaml - name: Install direnv run: | curl -sfL https://direnv.net/install.sh | bash echo "$HOME/.local/bin" >> $GITHUB_PATH ``` -------------------------------- ### Install direnv to /usr/local Source: https://direnv.net/docs/development.html Install the built direnv project to the default /usr/local directory. This typically requires administrator privileges. ```bash $ make install ``` -------------------------------- ### Install Ruby Versions and Create Aliases Source: https://direnv.net/docs/ruby.html Installs multiple Ruby versions using ruby-install and creates symbolic links for convenience. This prepares your system for version management. ```bash brew install ruby-install ruby-install ruby 1.9 ruby-install ruby 2.0 cd ~/.rubies ln -s 1.9.3-p448 1.9.3 ln -s 1.9.3-p448 1.9 ln -s 2.0.0-p247 2.0.0 ln -s 2.0.0-p247 2.0 ``` -------------------------------- ### Install direnv to Custom Location Source: https://direnv.net/docs/development.html Install the built direnv project to a custom location, such as ~/.local, by specifying the PREFIX variable. ```bash $ make install PREFIX=~/.local ``` -------------------------------- ### Elvish Setup for direnv Source: https://direnv.net/docs/hook.html Set up direnv for Elvish by creating a lib directory and hook file, then sourcing it in your rc.elv. ```bash ~> mkdir -p ~/.config/elvish/lib ~> direnv hook elvish > ~/.config/elvish/lib/direnv.elv ``` -------------------------------- ### direnv Example Workflow Source: https://direnv.net/man/direnv.1.html Demonstrates the typical workflow of using direnv to set and unset environment variables for a project. It shows how direnv prompts for allowance and reloads variables when entering and leaving a directory. ```bash $ cd ~/my_project $ echo ${FOO-nope} nope $ echo export FOO=foo > .envrc \.envrc is not allowed $ direnv allow . direnv: reloading direnv: loading .envrc direnv export: +FOO $ echo ${FOO-nope} foo $ cd .. direnv: unloading direnv export: ~PATH $ echo ${FOO-nope} nope ``` -------------------------------- ### Install direnv using apt-get on Ubuntu Source: https://direnv.net/docs/github-actions.html Installs direnv on Ubuntu runners using the apt-get package manager. ```yaml - name: Install direnv run: sudo apt-get update && sudo apt-get install -y direnv ``` -------------------------------- ### Install a specific version of direnv Source: https://direnv.net/docs/github-actions.html Installs a specific version of direnv by downloading the binary, making it executable, and moving it to the PATH. ```yaml - name: Install direnv run: | wget -O direnv https://github.com/direnv/direnv/releases/download/v2.34.0/direnv.linux-amd64 chmod +x direnv sudo mv direnv /usr/local/bin/ ``` -------------------------------- ### use flake Source: https://direnv.net/man/direnv-stdlib.1.md Loads the build environment of a derivation similar to `nix develop`, supporting default flakes or installables. ```APIDOC ## `use flake []` Load the build environment of a derivation similar to `nix develop`. By default it will load the current folder flake.nix devShell attribute. Or pass an "installable" like "nixpkgs#hello" to load all the build dependencies of the hello package from the latest nixpkgs. Note that the flakes feature is hidden behind an experimental flag, which you will have to enable on your own. Flakes is not considered stable yet. ``` -------------------------------- ### Install direnv and Configure Bash Source: https://direnv.net/docs/ruby.html Installs direnv using Homebrew and configures your .bashrc to load the direnv shell extension. Reload your shell for changes to take effect. ```bash brew install direnv echo 'eval $(direnv hook bash)' >> .bashrc exec $0 ``` -------------------------------- ### Select Ruby Version in Project Source: https://direnv.net/docs/ruby.html Add `use ruby ` to your project's `.envrc` file to automatically select the desired Ruby version when you enter the directory. direnv will handle the environment setup. ```bash use ruby 1.9.3 ``` -------------------------------- ### Elvish Shell Hook Setup Source: https://direnv.net/man/direnv.1.html Sets up direnv for the Elvish shell by creating a hook file and importing it in the rc.elv configuration. ```elvish ~> mkdir -p ~/.config/elvish/lib ~> direnv hook elvish > ~/.config/elvish/lib/direnv.elv ``` ```elvish use direnv ``` -------------------------------- ### Install direnv using Homebrew on macOS Source: https://direnv.net/docs/github-actions.html Installs direnv on macOS runners using the Homebrew package manager. ```yaml - name: Install direnv run: brew install direnv ``` -------------------------------- ### Load Nix flake build environment with use flake Source: https://direnv.net/man/direnv-stdlib.1.md Use `use flake` to load the build environment of a derivation, similar to `nix develop`. It can load the current folder's flake.nix or a specified installable. ```bash use flake [] ``` -------------------------------- ### Run direnv Tests Source: https://direnv.net/ Commands to run the tests for direnv. This may require installing Homebrew. ```bash brew bundle make test ``` -------------------------------- ### load_prefix Source: https://direnv.net/man/direnv-stdlib.1.md Expands common path variables for a given prefix path, useful for installed software. ```APIDOC ## `load_prefix ` Expands some common path variables for the given *prefix_path* prefix. This is useful if you installed something in the *prefix_path* using `./configure --prefix=$prefix_path && make install` and want to use it in the project. Variables set: CPATH LD_LIBRARY_PATH LIBRARY_PATH MANPATH PATH PKG_CONFIG_PATH Example: ./configure --prefix=$HOME/rubies/ruby-1.9.3 make && make install # Then in the .envrc load_prefix ~/rubies/ruby-1.9.3 ``` -------------------------------- ### Complete Node.js Workflow with direnv Source: https://direnv.net/docs/github-actions.html A comprehensive GitHub Actions workflow for a Node.js project that includes direnv setup, environment variable loading, and running tests and linting. ```yaml name: Node.js CI on: push: branches: [ main ] pull_request: branches: [ main ] jobs: test: runs-on: ubuntu-latest strategy: matrix: node-version: [18.x, 20.x] steps: - uses: actions/checkout@v4 - name: Install direnv run: | curl -sfL https://direnv.net/install.sh | bash echo "$HOME/.local/bin" >> $GITHUB_PATH - name: Setup Node.js $ uses: actions/setup-node@v4 with: node-version: $ - name: Load environment run: | # Create .envrc if it doesn't exist if [ ! -f .envrc ]; then cat > .envrc <<'EOF' export NODE_ENV=test export DATABASE_URL="postgresql://localhost/test_db" PATH_add node_modules/.bin EOF fi direnv allow . direnv export gha >> "$GITHUB_ENV" - name: Install dependencies run: npm ci - name: Run tests run: npm test - name: Run linter run: npm run lint ``` -------------------------------- ### Update gomod2nix.toml using Docker Source: https://direnv.net/docs/development.html Update the gomod2nix.toml file by executing the provided script. If Nix is not installed locally, this command demonstrates how to use a Docker container to run the script. ```bash $ docker run -it --platform linux/amd64 -v $(pwd):/workdir nixos/nix /bin/sh -c "cd workdir && ./script/update-gomod2nix" ``` -------------------------------- ### Fetch URL to Disk Location Source: https://direnv.net/man/direnv-fetchurl.1.html Invoke fetchurl again with the URL and its integrity hash to get the on-disk location. The downloaded file is marked as read-only and executable. ```bash direnv fetchurl "https://releases.nixos.org/nix/nix-2.3.7/install" "sha256-7Gxl5GzI9juc/U30Igh/pY+p6+gj5Waohfwql3jHIds=" #=> /home/zimbatm/.cache/direnv/cas/sha256-7Gxl5GzI9juc_U30Igh_pY+p6+gj5Waohfwql3jHIds= ``` -------------------------------- ### find_up Source: https://direnv.net/man/direnv-stdlib.1.md Searches for a file starting from the current directory upwards to the root. ```APIDOC ## find_up ### Description Outputs the path of *filename* when searched from the current directory up to /. Returns 1 if the file has not been found. ### Example ```bash cd /usr/local/my mkdir -p project/foo touch bar cd project/foo find_up bar # output: /usr/local/my/bar ``` ``` -------------------------------- ### Expand common path variables with load_prefix Source: https://direnv.net/man/direnv-stdlib.1.md Use `load_prefix` to expand common path variables (CPATH, LD_LIBRARY_PATH, etc.) based on a given installation prefix. This is useful after installing software with a custom prefix. ```bash # Then in the .envrc load_prefix ~/rubies/ruby-1.9.3 ``` -------------------------------- ### Clone direnv Repository Source: https://direnv.net/docs/development.html Clone the direnv project from GitHub. Ensure you have Git installed. ```bash $ git clone git@github.com:direnv/direnv.git ``` -------------------------------- ### Troubleshoot direnv permission errors in GitHub Actions Source: https://direnv.net/docs/github-actions.html This step ensures direnv is installed, added to the PATH, and allowed to load .envrc files, addressing potential permission denied errors. ```yaml - name: Install and setup direnv run: | curl -sfL https://direnv.net/install.sh | bash echo "$HOME/.local/bin" >> $GITHUB_PATH # Force PATH update in current step export PATH="$HOME/.local/bin:$PATH" direnv allow . direnv export gha >> "$GITHUB_ENV" ``` -------------------------------- ### Check Git Branch Source: https://direnv.net/man/direnv-stdlib.1.md Returns 0 if within a git repository with the specified branch name, or any branch if no name is provided. Requires git to be installed. Watching '.git/HEAD' triggers reloads when entering/exiting branches. ```bash if on_git_branch child_changes; then export MERGE_BASE_BRANCH=parent_changes fi if on_git_branch; then echo "Thanks for contributing to a GitHub project!" fi ``` -------------------------------- ### Find file path upwards with `find_up` Source: https://direnv.net/man/direnv-stdlib.1.md Searches for a given filename starting from the current directory and moving upwards towards the root directory. Returns the absolute path of the file if found, otherwise returns 1. ```bash cd /usr/local/my mkdir -p project/foo touch bar cd project/foo find_up bar # output: /usr/local/my/bar ``` -------------------------------- ### Quick direnv Demo Source: https://direnv.net/ Demonstrates the basic usage of direnv, including creating a project directory, setting an environment variable in .envrc, allowing its execution, and verifying the variable is loaded and unloaded. ```bash # Create a new folder for demo purposes. $ mkdir ~/my-project $ cd ~/my-project # Show that the FOO environment variable is not loaded. $ echo ${FOO-nope} nope # Create a new .envrc. This file is bash code that is going to be loaded by # direnv. $ echo export FOO=foo > .envrc .envrc is not allowed # The security mechanism didn't allow to load the .envrc. Since we trust it, # let's allow its execution. $ direnv allow . direnv: reloading direnv: loading .envrc direnv export: +FOO # Show that the FOO environment variable is loaded. $ echo ${FOO-nope} foo # Exit the project $ cd .. direnv: unloading # And now FOO is unset again $ echo ${FOO-nope} nope ``` -------------------------------- ### Basic TOML Configuration Structure Source: https://direnv.net/man/direnv.toml.1.html Illustrates the fundamental structure of a TOML configuration file with a sample section and key-value pair. ```toml [section] key = "value" ``` -------------------------------- ### Build direnv Project Source: https://direnv.net/docs/development.html Navigate to the cloned direnv directory and build the project using 'make'. Go version 1.24 or higher is required. ```bash $ cd direnv $ make ``` -------------------------------- ### use Source: https://direnv.net/man/direnv-stdlib.1.md A semantic command dispatch intended for loading external dependencies into the environment. ```APIDOC ## `use []` A semantic command dispatch intended for loading external dependencies into the environment. Example: use_ruby() { echo "Ruby $1" } use ruby 1.9.3 # output: Ruby 1.9.3 ``` -------------------------------- ### Configure Go project layout with layout go Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout go` to automatically add the Go workspace directory to GOPATH and the project's bin directory to PATH. ```bash layout go ``` -------------------------------- ### use nix Source: https://direnv.net/man/direnv-stdlib.1.md Loads environment variables from nix-shell, supporting default.nix/shell.nix or direct package specification. ```APIDOC ## `use nix [...]` Load environment variables from `nix-shell`. If you have a `default.nix` or `shell.nix` these will be used by default, but you can also specify packages directly (e.g `use nix -p ocaml`). See http://nixos.org/nix/manual/#sec-nix-shell ``` -------------------------------- ### Configure PHP project layout with layout php Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout php` to add the vendor/bin directory to the PATH, making PHP executables available. ```bash layout php ``` -------------------------------- ### Fetch URL to disk with `fetchurl` Source: https://direnv.net/man/direnv-stdlib.1.md Fetches a URL to a local file and outputs the file path. Optionally verifies the integrity of the fetched content using an integrity hash. ```bash fetchurl https://example.com/data.txt sha256:abcdef123456 ``` -------------------------------- ### layout perl Source: https://direnv.net/man/direnv-stdlib.1.md Sets up environment variables required by perl's local::lib. ```APIDOC ## `layout perl` Setup environment variables required by perl's local::lib See http://search.cpan.org/dist/local-lib/lib/local/lib.pm for more details. ``` -------------------------------- ### layout python Source: https://direnv.net/man/direnv-stdlib.1.md Creates and loads a virtualenv environment under $PWD/.direnv/python-$python_version. ```APIDOC ## `layout python []` Creates and loads a virtualenv environment under `$PWD/.direnv/python-$python_version`. This forces the installation of any egg into the project's sub-folder. It's possible to specify the python executable if you want to use different versions of python (eg: `layout python python3`). Note that previously virtualenv was located under `$PWD/.direnv/virtualenv` and will be re-used by direnv if it exists. ``` -------------------------------- ### use julia Source: https://direnv.net/man/direnv-stdlib.1.md Loads the specified Julia version, searching if necessary. ```APIDOC ## `use julia ` Loads the specified Julia version. You must specify a path to the directory with installed Julia versions using $JULIA_VERSIONS. You can optionally override the prefix for folders inside $JULIA_VERSIONS (default `julia-`) using $JULIA_VERSION_PREFIX. If no exact match for `` is found a search will be performed and the latest version will be loaded. Examples (.envrc): use julia 1.5.1 # loads $JULIA_VERSIONS/julia-1.5.1 use julia 1.5 # loads $JULIA_VERSIONS/julia-1.5.1 use julia master # loads $JULIA_VERSIONS/julia-master ``` -------------------------------- ### Configure Node.js project layout with layout node Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout node` to add the local node_modules/.bin directory to the PATH, making Node.js executables available. ```bash layout node ``` -------------------------------- ### Load Nix environment with use nix Source: https://direnv.net/man/direnv-stdlib.1.md Use `use nix` to load environment variables from `nix-shell`. It can use default Nix files or specify packages directly. ```bash use nix [...] ``` -------------------------------- ### use rbenv Source: https://direnv.net/man/direnv-stdlib.1.md Loads rbenv, adding ruby wrappers to the PATH. ```APIDOC ## `use rbenv` Loads rbenv which add the ruby wrappers available on the PATH. ``` -------------------------------- ### Load external dependencies with use Source: https://direnv.net/man/direnv-stdlib.1.md Use `use` as a semantic command dispatch for loading external dependencies. It can be used with specific programs like `ruby` or `julia`. ```bash use_ruby() { echo "Ruby $1" } use ruby 1.9.3 ``` -------------------------------- ### layout ruby Source: https://direnv.net/man/direnv-stdlib.1.md Sets GEM_HOME for Ruby projects and creates bundler wrappers. ```APIDOC ## `layout ruby` Sets the GEM_HOME environment variable to `$PWD/.direnv/ruby/RUBY_VERSION`. This forces the installation of any gems into the project's sub-folder. If you're using bundler it will create wrapper programs that can be invoked directly instead of using the `bundle exec` prefix. ``` -------------------------------- ### Configure Ruby project layout with layout ruby Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout ruby` to set GEM_HOME to manage gems within the project and enable direct invocation of bundled executables. ```bash layout ruby ``` -------------------------------- ### Configure Julia project layout with layout julia Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout julia` to set the JULIA_PROJECT environment variable to the current directory, facilitating Julia project management. ```bash layout julia ``` -------------------------------- ### Configure Perl project layout with layout perl Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout perl` to set up environment variables required by Perl's local::lib for managing local Perl modules. ```bash layout perl ``` -------------------------------- ### source_env Source: https://direnv.net/man/direnv-stdlib.1.md Loads another .envrc file or directory. ```APIDOC ## source_env ### Description Loads another `.envrc` either by specifying its path or filename. NOTE: the other `.envrc` is not checked by the security framework. ``` -------------------------------- ### dotenv [] Source: https://direnv.net/man/direnv-stdlib.1.md Loads a .env file into the current environment. ```APIDOC ## dotenv [] ### Description Loads a ".env" file into the current environment. ``` -------------------------------- ### Load Environment with Guix Source: https://direnv.net/man/direnv-stdlib.1.md Loads environment variables from 'guix shell'. Any arguments are passed to 'guix shell'. Use '--development' for dependencies or '--file' to load from a file. ```bash use guix hello use guix --development hello ``` -------------------------------- ### layout go Source: https://direnv.net/man/direnv-stdlib.1.md Adds layout directory to GOPATH and bin to PATH for Go projects. ```APIDOC ## `layout go` Adds "$(direnv_layout_dir)/go" to the GOPATH environment variable. And also adds "$PWD/bin" to the PATH environment variable. ``` -------------------------------- ### Load Julia versions with use julia Source: https://direnv.net/man/direnv-stdlib.1.md Use `use julia` to load a specified Julia version. It searches for the version in $JULIA_VERSIONS and can load the latest if an exact match is not found. ```bash use julia 1.5.1 # loads $JULIA_VERSIONS/julia-1.5.1 ``` ```bash use julia 1.5 # loads $JULIA_VERSIONS/julia-1.5.1 ``` ```bash use julia master # loads $JULIA_VERSIONS/julia-master ``` -------------------------------- ### Source another .envrc file with `source_env` Source: https://direnv.net/man/direnv-stdlib.1.md Loads another `.envrc` file into the current environment. Note that the sourced `.envrc` is not checked by the security framework. ```bash source_env .envrc.prod ``` -------------------------------- ### Load rbenv with use rbenv Source: https://direnv.net/man/direnv-stdlib.1.md Use `use rbenv` to load rbenv, which adds Ruby wrappers to the PATH for managing Ruby versions. ```bash use rbenv ``` -------------------------------- ### source_env_if_exists Source: https://direnv.net/man/direnv-stdlib.1.md Loads another .envrc file if it exists. ```APIDOC ## source_env_if_exists ### Description Loads another ".envrc", but only if it exists. NOTE: contrary to `source_env`, this only works when passing a path to a file, not a directory. ### Example ```bash source_env_if_exists .envrc.private ``` ``` -------------------------------- ### source_up_if_exists [] Source: https://direnv.net/man/direnv-stdlib.1.md Loads another .envrc file if found by searching upwards, does nothing if not found. ```APIDOC ## source_up_if_exists [] ### Description Loads another `.envrc` if found with the find_up command. If one is not found, nothing happens. NOTE: the other `.envrc` is not checked by the security framework. ``` -------------------------------- ### Source URL with integrity check using `source_url` Source: https://direnv.net/man/direnv-stdlib.1.md Loads a script from a given URL after verifying its integrity using the provided hash. Use `direnv fetchurl ` to obtain the integrity hash. ```bash source_url https://example.com/script.sh sha256:abcdef123456 ``` -------------------------------- ### Load .env file with `dotenv` Source: https://direnv.net/man/direnv-stdlib.1.md Loads a `.env` file into the current environment. If no path is specified, it defaults to looking for a file named `.env`. ```bash dotenv ``` -------------------------------- ### layout php Source: https://direnv.net/man/direnv-stdlib.1.md Adds vendor/bin to the PATH for PHP projects. ```APIDOC ## `layout php` Adds "$PWD/vendor/bin" to the PATH environment variable. ``` -------------------------------- ### direnv_apply_dump Source: https://direnv.net/man/direnv-stdlib.1.md Loads environment variables from the output of `direnv dump` stored in a file. ```APIDOC ## direnv_apply_dump ### Description Loads the output of `direnv dump` that was stored in a file. ``` -------------------------------- ### Load Node.js Version Source: https://direnv.net/man/direnv-stdlib.1.md Loads a specified Node.js version into the environment. If no version is given, it checks for '.nvmrc' or '.node-version' files. Requires the $NODE_VERSIONS environment variable to be set. ```bash use node use node 4.2 use node ``` -------------------------------- ### source_up [] Source: https://direnv.net/man/direnv-stdlib.1.md Loads another .envrc file found by searching upwards from the current directory. ```APIDOC ## source_up [] ### Description Loads another `.envrc` if found with the find_up command. Returns 1 if no file is found. NOTE: the other `.envrc` is not checked by the security framework. ``` -------------------------------- ### layout opam Source: https://direnv.net/man/direnv-stdlib.1.md Sets environment variables from opam env for OCaml projects. ```APIDOC ## `layout opam` Sets environment variables from `opam env`. ``` -------------------------------- ### fetchurl [] Source: https://direnv.net/man/direnv-stdlib.1.md Fetches a URL to disk, optionally verifying its integrity. ```APIDOC ## fetchurl [] ### Description Fetches the given `url` onto disk and outputs its path location on stdout. If the `integrity-hash` argument is provided, it will also check the integrity of the script. See also `direnv-fetchurl(1)` for more details. ``` -------------------------------- ### direnv_load [] Source: https://direnv.net/man/direnv-stdlib.1.md Applies environment changes generated by a command that outputs direnv dump format. ```APIDOC ## direnv_load [] ### Description Applies the environment generated by running *argv* as a command. This is useful for adopting the environment of a child process - cause that process to run "direnv dump" and then wrap the results with direnv_load. ### Example ```bash direnv_load opam exec direnv dump ``` ``` -------------------------------- ### dotenv_if_exists [] Source: https://direnv.net/man/direnv-stdlib.1.md Loads a .env file into the current environment only if it exists. ```APIDOC ## dotenv_if_exists [] ### Description Loads a ".env" file into the current environment, but only if it exists. ``` -------------------------------- ### Configure Python virtualenv with layout python Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout python` to create and load a virtualenv under the project's .direnv directory. You can specify a Python executable to use a different version. ```bash layout python [] ``` ```bash layout python3 ``` -------------------------------- ### Configure Pyenv virtualenv with layout pyenv Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout pyenv` to create and load a virtualenv using pyenv with specified Python interpreter versions. Multiple versions can be specified. ```bash layout pyenv [ ...] ``` -------------------------------- ### Conditionally source .envrc file upwards with `source_up_if_exists` Source: https://direnv.net/man/direnv-stdlib.1.md Searches for another `.envrc` file using `find_up` and loads it if found. If no file is found, no action is taken. The sourced `.envrc` is not checked by the security framework. ```bash source_up_if_exists .envrc.fallback ``` -------------------------------- ### layout python3 Source: https://direnv.net/man/direnv-stdlib.1.md A shortcut for layout python python3. ```APIDOC ## `layout python3` A shortcut for `layout python python3` ``` -------------------------------- ### Whitelist Directory Prefixes Source: https://direnv.net/man/direnv.toml.1.html Configures direnv to automatically trust .envrc files within specified directory prefixes. Use with caution as it bypasses explicit 'direnv allow' commands. ```toml [whitelist] prefix = [ "/home/user/code/project-a", "~/code/project-b" ] ``` -------------------------------- ### Test direnv Project Source: https://direnv.net/docs/development.html Run the project tests after building. Ensure the build step is completed successfully before running tests. ```bash $ make test ``` -------------------------------- ### Fish Hook for direnv Source: https://direnv.net/docs/hook.html Add this line to your ~/.config/fish/config.fish file to enable direnv for Fish. The hook can be configured with the direnv_fish_mode variable. ```fish direnv hook fish | source ``` -------------------------------- ### Source .envrc file upwards with `source_up` Source: https://direnv.net/man/direnv-stdlib.1.md Searches for and loads another `.envrc` file using the `find_up` command. Returns 1 if no file is found. The sourced `.envrc` is not checked by the security framework. ```bash source_up ``` -------------------------------- ### Whitelist Exact .envrc Files or Directories Source: https://direnv.net/man/direnv.toml.1.html Specifies exact .envrc files or directories that direnv should automatically trust. This provides more granular control than prefix whitelisting. ```toml [whitelist] exact = [ "/home/user/project-a/.envrc", "~/project-b/subdir-a" ] ``` -------------------------------- ### layout node Source: https://direnv.net/man/direnv-stdlib.1.md Adds node_modules/.bin to the PATH for Node.js projects. ```APIDOC ## `layout node` Adds "$PWD/node_modules/.bin" to the PATH environment variable. ``` -------------------------------- ### Configure Pipenv project layout with layout pipenv Source: https://direnv.net/man/direnv-stdlib.1.md Use `layout pipenv` to create and load a virtualenv using Pipenv based on the Pipfile. It mimics `dotenv .env` behavior if a .env file exists. ```bash layout pipenv ``` -------------------------------- ### layout julia Source: https://direnv.net/man/direnv-stdlib.1.md Sets the JULIA_PROJECT environment variable to the current directory for Julia projects. ```APIDOC ## `layout julia` Sets the `JULIA_PROJECT` environment variable to the current directory. ``` -------------------------------- ### source_url Source: https://direnv.net/man/direnv-stdlib.1.md Loads a script from a URL after verifying its integrity hash. ```APIDOC ## source_url ### Description Loads another script from the given `url`. Before loading it will check the integrity using the provided `integrity-hash`. To find the value of the `integrity-hash`, call `direnv fetchurl ` and extract the hash from the outputted message. See also `direnv-fetchurl(1)` for more details. ``` -------------------------------- ### layout Source: https://direnv.net/man/direnv-stdlib.1.md A semantic dispatch used to describe common project layouts. ```APIDOC ## `layout ` A semantic dispatch used to describe common project layouts. ``` -------------------------------- ### path_add Source: https://direnv.net/man/direnv-stdlib.1.md Prepends a path to an arbitrary environment variable, similar to PATH_add. ```APIDOC ## path_add ### Description Works like `PATH_add` except that it's for an arbitrary *varname*. ``` -------------------------------- ### Define Custom direnv Ruby Version Loader Source: https://direnv.net/docs/ruby.html Defines a custom `use_ruby` function in `~/.config/direnv/direnvrc`. This function loads the specified Ruby version into the environment and sets up the Ruby layout for gem management within the project. ```bash # Usage: use ruby # # Loads the specified ruby version into the environment # use_ruby() { local ruby_dir=$HOME/.rubies/$1 load_prefix $ruby_dir layout ruby } ``` -------------------------------- ### PATH_add Source: https://direnv.net/man/direnv-stdlib.1.md Prepends a path to the PATH environment variable, ensuring existing paths are preserved. ```APIDOC ## PATH_add ### Description Prepends the expanded *path* to the PATH environment variable. It prevents a common mistake where PATH is replaced by only the new *path*. ### Example ```bash pwd # output: /home/user/my/project PATH_add bin echo $PATH # output: /home/user/my/project/bin:/usr/bin:/bin ``` ``` -------------------------------- ### Oh My Zsh direnv Plugin Source: https://direnv.net/docs/hook.html To enable direnv support in Oh My Zsh, add 'direnv' to the plugins array in your zshrc file. ```zsh plugins=(... direnv) ``` -------------------------------- ### Conditionally load .env file with `dotenv_if_exists` Source: https://direnv.net/man/direnv-stdlib.1.md Loads a `.env` file into the current environment only if the file exists. This prevents errors if the file is not present. ```bash dotenv_if_exists .env.local ``` -------------------------------- ### PowerShell Hook for direnv Source: https://direnv.net/docs/hook.html Add this line to your $PROFILE to enable direnv for PowerShell. ```powershell Invoke-Expression "$(direnv hook pwsh)" ``` -------------------------------- ### Require Allowed Files for Security Source: https://direnv.net/man/direnv-stdlib.1.md Adds a list of files to the allow-list for '.envrc'. If any specified files are modified, removed, or new files appear, 'direnv allow' must be re-run. This enhances security for environments executing code from lockfiles. ```bash require_allowed pixi.toml pixi.lock ``` -------------------------------- ### Apply environment from a command with `direnv_load` Source: https://direnv.net/man/direnv-stdlib.1.md Applies the environment generated by executing a command. This is useful for adopting the environment of a child process by having it run `direnv dump` and then wrapping the output with `direnv_load`. ```bash direnv_load opam exec direnv dump ``` -------------------------------- ### Zsh Hook for direnv Source: https://direnv.net/docs/hook.html Add this line to your ~/.zshrc file to enable direnv for Zsh. ```zsh eval "$(direnv hook zsh)" ``` -------------------------------- ### Murex Hook for direnv Source: https://direnv.net/docs/hook.html Add this line to your ~/.murex_profile file to enable direnv for Murex. ```murex direnv hook murex -> source ``` -------------------------------- ### Conditionally source .envrc file with `source_env_if_exists` Source: https://direnv.net/man/direnv-stdlib.1.md Loads another `.envrc` file only if it exists. This function requires a path to a file, not a directory. ```bash source_env_if_exists .envrc.private ``` -------------------------------- ### has Source: https://direnv.net/man/direnv-stdlib.1.md Checks if a command (binary or shell function) is available in the environment. ```APIDOC ## has ### Description Returns 0 if the *command* is available. Returns 1 otherwise. It can be a binary in the PATH or a shell function. ### Example ```bash if has curl; then echo "Yes we do" fi ``` ``` -------------------------------- ### Apply dumped environment with `direnv_apply_dump` Source: https://direnv.net/man/direnv-stdlib.1.md Loads environment variables from the output of `direnv dump` that has been previously stored in a file. ```bash direnv_apply_dump /path/to/dumped_env ``` -------------------------------- ### layout pipenv Source: https://direnv.net/man/direnv-stdlib.1.md Uses Pipenv to build a virtualenv from Pipfile, with optional PIPENV_PIPFILE override. ```APIDOC ## `layout pipenv` Similar to `layout python`, but uses Pipenv to build a virtualenv from the `Pipfile` located in the same directory. The path can be overridden by the `PIPENV_PIPFILE` environment variable. Note that unlike invoking Pipenv manually, this does not load environment variables from a `.env` file automatically. You may want to add `dotenv .env` to copy that behavior. ``` -------------------------------- ### Elvish rc.elv Configuration for direnv Source: https://direnv.net/docs/hook.html Add this line to your ~/.config/elvish/rc.elv file to use direnv in Elvish. ```elvish use direnv ``` -------------------------------- ### Search for highest SemVer version with semver_search Source: https://direnv.net/man/direnv-stdlib.1.md Use `semver_search` to find the highest version number matching a SemVer pattern within a directory and with a specific folder prefix. It can match partial versions. ```bash semver_search "dir" "program-" "1.4.0" ``` ```bash semver_search "dir" "program-" "1.4" ``` ```bash semver_search "dir" "program-" "1" ``` -------------------------------- ### MANPATH_add Source: https://direnv.net/man/direnv-stdlib.1.md Prepends a path to the MANPATH environment variable, handling man-specific heuristics. ```APIDOC ## MANPATH_add ### Description Prepends the expanded *path* to the MANPATH environment variable. It takes care of man-specific heuristics. ``` -------------------------------- ### Bash Hook for direnv Source: https://direnv.net/docs/hook.html Add this line to your ~/.bashrc file to enable direnv for Bash. Ensure it is placed after other shell extensions that might modify the prompt. ```bash eval "$(direnv hook bash)" ``` -------------------------------- ### Watch File for Changes Source: https://direnv.net/man/direnv-stdlib.1.md Adds specified files to direnv's watch-list. If any of these files change, direnv will reload the environment on the next prompt. ```bash watch_file Gemfile ``` -------------------------------- ### Correctly export direnv variables to GitHub Actions environment Source: https://direnv.net/docs/github-actions.html Ensures direnv environment variables are correctly exported to the GitHub Actions environment file using `> "$GITHUB_ENV"`. ```bash # Correct direnv export gha > "$GITHUB_ENV" ``` -------------------------------- ### layout pyenv Source: https://direnv.net/man/direnv-stdlib.1.md Uses pyenv to build a virtualenv with specified Python interpreter versions. ```APIDOC ## `layout pyenv [ ...]` Similar to `layout python`, but uses pyenv to build a virtualenv with the specified Python interpreter version. Multiple versions may be specified separated by spaces; please refer to the pyenv documentation for more information. ``` -------------------------------- ### Check Minimum Direnv Version Source: https://direnv.net/man/direnv-stdlib.1.md Checks that the direnv version is at least the specified version. This is useful for ensuring users have a compatible direnv version when sharing '.envrc' files. ```bash direnv_version ``` -------------------------------- ### Prepend Vim Script Source: https://direnv.net/man/direnv-stdlib.1.md Prepends a specified vim script or '.vimrc.local' to the DIRENV_EXTRA_VIMRC environment variable, which is used by the direnv/direnv.vim extension. ```bash use vim [] ``` -------------------------------- ### Debug direnv issues in GitHub Actions Source: https://direnv.net/docs/github-actions.html Commands to help debug direnv issues by checking version, status, .envrc content, and exporting variables. ```yaml - name: Debug direnv run: | direnv version direnv status cat .envrc direnv allow . direnv export gha ``` -------------------------------- ### Discover URL Integrity Hash Source: https://direnv.net/man/direnv-fetchurl.1.html Use this command to discover the integrity hash of a URL. If stdout is not a tty, only the hash will be displayed. ```bash $ ./direnv fetchurl https://releases.nixos.org/nix/nix-2.3.7/install Found hash: sha256-7Gxl5GzI9juc/U30Igh/pY+p6+gj5Waohfwql3jHIds= ``` -------------------------------- ### Tcsh Hook for direnv Source: https://direnv.net/docs/hook.html Add this line to your ~/.cshrc file to enable direnv for Tcsh. ```tcsh eval `direnv hook tcsh` ``` -------------------------------- ### expand_path [] Source: https://direnv.net/man/direnv-stdlib.1.md Outputs the absolute path of a relative path, optionally relative to another directory. ```APIDOC ## expand_path [] ### Description Outputs the absolute path of *rel_path* relative to *relative_to* or the current directory. ### Example ```bash cd /usr/local/games expand_path ../foo # output: /usr/local/foo ``` ``` -------------------------------- ### user_rel_path Source: https://direnv.net/man/direnv-stdlib.1.md Transforms an absolute path into a user-relative path (e.g., ~/...) if possible. ```APIDOC ## user_rel_path ### Description Transforms an absolute path *abs_path* into a user-relative path if possible. ### Example ```bash echo $HOME # output: /home/user user_rel_path /home/user/my/project # output: ~/my/project user_rel_path /usr/local/lib # output: /usr/local/lib ``` ``` -------------------------------- ### Transform absolute path to user-relative path with `user_rel_path` Source: https://direnv.net/man/direnv-stdlib.1.md The `user_rel_path` function converts an absolute path to a user-relative path (e.g., `~/my/project`) if it falls within the user's home directory. Otherwise, it returns the original absolute path. ```bash echo $HOME # output: /home/user user_rel_path /home/user/my/project # output: ~/my/project user_rel_path /usr/local/lib # output: /usr/local/lib ``` -------------------------------- ### Expand relative path with `expand_path` Source: https://direnv.net/man/direnv-stdlib.1.md The `expand_path` function outputs the absolute path of a relative path, optionally relative to another directory. If `relative_to` is not provided, it uses the current directory. ```bash cd /usr/local/games expand_path ../foo # output: /usr/local/foo ``` -------------------------------- ### Fish direnv Mode Configuration Source: https://direnv.net/docs/hook.html Configure the behavior of direnv with directory changes in Fish using the direnv_fish_mode variable. Options include 'eval_on_arrow' (default), 'eval_after_arrow', and 'disable_arrow'. ```fish set -g direnv_fish_mode eval_on_arrow # trigger direnv at prompt, and on every arrow-based directory change (default) ``` ```fish set -g direnv_fish_mode eval_after_arrow # trigger direnv at prompt, and only after arrow-based directory changes before executing command ``` ```fish set -g direnv_fish_mode disable_arrow # trigger direnv at prompt only, this is similar functionality to the original behavior ``` -------------------------------- ### semver_search Source: https://direnv.net/man/direnv-stdlib.1.md Searches a directory for the highest version number in SemVer format. ```APIDOC ## `semver_search ` Search a directory for the highest version number in SemVer format (X.Y.Z). Examples: $ tree . . |-- dir |-- program-1.4.0 |-- program-1.4.1 |-- program-1.5.0 $ semver_search "dir" "program-" "1.4.0" 1.4.0 $ semver_search "dir" "program-" "1.4" 1.4.1 $ semver_search "dir" "program-" "1" 1.5.0 ``` -------------------------------- ### Require environment variables with `env_vars_required` Source: https://direnv.net/man/direnv-stdlib.1.md Logs an error for each specified environment variable that is not set or is empty. Typically used after sourcing other `.envrc` files to ensure necessary variables are present. ```bash # expect .envrc.private to provide tokens source_env .envrc.private # check presence of tokens env_vars_required GITHUB_TOKEN OTHER_TOKEN ``` -------------------------------- ### Prepend to MANPATH with `MANPATH_add` Source: https://direnv.net/man/direnv-stdlib.1.md Prepends the expanded path to the MANPATH environment variable, taking into account man-specific heuristics for path searching. ```bash MANPATH_add /usr/local/share/man ``` -------------------------------- ### Check command availability with `has` Source: https://direnv.net/man/direnv-stdlib.1.md Use the `has` function to check if a command is available in the PATH or as a shell function. Returns 0 if available, 1 otherwise. ```bash if has curl; then echo "Yes we do" fi ``` -------------------------------- ### Add path to arbitrary variable with `path_add` Source: https://direnv.net/man/direnv-stdlib.1.md Similar to `PATH_add`, but works for any specified environment variable. It prepends the expanded path to the given variable. ```bash path_add MY_LIBS lib/utils ``` -------------------------------- ### Prepend to PATH with `PATH_add` Source: https://direnv.net/man/direnv-stdlib.1.md Prepends the expanded path to the PATH environment variable, ensuring that the new path is searched first. This prevents overwriting the existing PATH. ```bash pwd # output: /home/user/my/project PATH_add bin echo $PATH # output: /home/user/my/project/bin:/usr/bin:/bin ``` -------------------------------- ### env_vars_required [ ...] Source: https://direnv.net/man/direnv-stdlib.1.md Checks for the presence and non-empty value of specified environment variables. ```APIDOC ## env_vars_required [ ...] ### Description Logs error for every variable not present in the environment or having an empty value. Typically this is used in combination with source_env and source_env_if_exists. ### Example ```bash # expect .envrc.private to provide tokens source_env .envrc.private # check presence of tokens env_vars_required GITHUB_TOKEN OTHER_TOKEN ``` ``` -------------------------------- ### Enable Strict Shell Execution (Whole Script) Source: https://direnv.net/man/direnv-stdlib.1.md Turns on shell execution strictness for the entire '.envrc' evaluation context. Exits immediately if commands in a pipeline return non-zero or if un-declared variables are referenced. ```bash strict_env has curl ``` -------------------------------- ### Nushell Hook for direnv Source: https://direnv.net/docs/hook.html Add this hook to your $env.config.hooks.env_change.PWD list in config.nu for direnv integration in Nushell. It checks for direnv, exports environment variables, and loads them. ```nu { || if (which direnv | is-empty) { return } direnv export json | from json | default {} | load-env } ``` -------------------------------- ### Watch Directory Recursively Source: https://direnv.net/man/direnv-stdlib.1.md Adds a directory to direnv's recursive watch-list. If any file within the directory or its subdirectories changes, direnv will reload the environment on the next prompt. ```bash watch_dir src ``` -------------------------------- ### PATH_rm [ ...] Source: https://direnv.net/man/direnv-stdlib.1.md Removes directories matching specified patterns from the PATH environment variable. ```APIDOC ## PATH_rm [ ...] ### Description Removes directories that match any of the given shell patterns from the PATH environment variable. Order of the remaining directories is preserved in the resulting PATH. Bash pattern syntax: https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html ### Example ```bash echo $PATH # output: /dontremove/me:/remove/me:/usr/local/bin/:... PATH_rm '/remove/*' echo $PATH # output: /dontremove/me:/usr/local/bin/: ``` ``` -------------------------------- ### Enable Strict Shell Execution (Command) Source: https://direnv.net/man/direnv-stdlib.1.md Turns on shell execution strictness for the duration of a specific command. Exits immediately if commands in a pipeline return non-zero or if un-declared variables are referenced. ```bash strict_env has curl ``` -------------------------------- ### Disable Strict Shell Execution (Whole Script) Source: https://direnv.net/man/direnv-stdlib.1.md Turns off shell execution strictness for the entire '.envrc' evaluation context. ```bash unstrict_env has curl ``` -------------------------------- ### Remove paths from PATH with `PATH_rm` Source: https://direnv.net/man/direnv-stdlib.1.md Removes directories matching the given shell patterns from the PATH environment variable. The order of the remaining directories is preserved. ```bash echo $PATH # output: /dontremove/me:/remove/me:/usr/local/bin/:... PATH_rm '/remove/*' echo $PATH # output: /dontremove/me:/usr/local/bin/... ``` -------------------------------- ### Disable Strict Shell Execution (Command) Source: https://direnv.net/man/direnv-stdlib.1.md Turns off shell execution strictness for the duration of a specific command. ```bash unstrict_env has curl ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.