.TH DIRENV\-STDLIB 1 "APRIL 2014" direnv "User Manuals" .SH NAME .PP direnv\_stdlib \- the ".envrc" stdlib .SH SYNOPSIS .PP \fB\fCdirenv stdlib\fR .SH DESCRIPTION .PP Outputs a bash script called the \fIstdlib\fP\&. The following commands are included in that script and loaded in the context of an ".envrc". In addition, it also loads the file in "\~\&/.direnvrc" if it exists. .SH STDLIB.IP \(bu 2 \fB\fChas\fR \fIcommand\fP: Returns 0 if the \fIcommand\fP is available. Returns 1 otherwise. It can be a binary in the PATH or a shell function. .PP Example: .PP .RS .nf if has curl; then echo "Yes we do" fi .fi .RE .IP \(bu 2 \fB\fCexpand\_path\fR \fIrel\_path\fP [\fIrelative\_to\fP]: Outputs the absolute path of \fIrel\_path\fP relative to \fIrelative\_to\fP or the current directory. .PP Example: .PP .RS .nf cd /usr/local/games expand\_path ../foo # output: /usr/local/foo .fi .RE .IP \(bu 2 .PP \fB\fCdotenv\fR [\fIdotenv\_path\fP]: Loads a ".env" file into the current environment .IP \(bu 2 .PP \fB\fCuser\_rel\_path\fR \fIabs\_path\fP: Transforms an absolute path \fIabs\_path\fP into a user\-relative path if possible. .PP Example: .PP .RS .nf 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 .fi .RE .IP \(bu 2 \fB\fCfind\_up\fR \fIfilename\fP: Outputs the path of \fIfilename\fP when searched from the current directory up to /. Returns 1 if the file has not been found. .PP Example: .PP .RS .nf cd /usr/local/my mkdir \-p project/foo touch bar cd project/foo find\_up bar # output: /usr/local/my/bar .fi .RE .IP \(bu 2 .PP \fB\fCsource\_env\fR \fIfile\_or\_dir\_path\fP: Loads another ".envrc" either by specifying its path or filename. .IP \(bu 2 .PP \fB\fCsource\_up\fR [\fIfilename\fP]: Loads another ".envrc" if found with the \fB\fCfind\_up\fR command. .IP \(bu 2 .PP \fB\fCdirenv\_load\fR [\fIcommand\-generating\-dump\-output\fP] Applies the environment generated by running \fIargv\fP 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. .PP Example: .PP .RS .nf direnv\_load opam\-env exec \-\- direnv dump .fi .RE .IP \(bu 2 \fB\fCPATH\_add\fR \fIpath\fP: Prepends the expanded \fIpath\fP to the PATH environment variable. It prevents a common mistake where PATH is replaced by only the new \fIpath\fP\&. .PP Example: .PP .RS .nf pwd # output: /home/user/my/project PATH\_add bin echo $PATH # output: /home/user/my/project/bin:/usr/bin:/bin .fi .RE .IP \(bu 2 .PP \fB\fCpath\_add\fR \fIvarname\fP \fIpath\fP: Works like \fB\fCPATH\_add\fR except that it's for an arbitrary \fIvarname\fP\&. .IP \(bu 2 .PP \fB\fCload\_prefix\fR \fIprefix\_path\fP: Expands some common path variables for the given \fIprefix\_path\fP prefix. This is useful if you installed something in the \fIprefix\_path\fP using \fB\fC\&./configure \-\&\-\&prefix=$prefix\_\&path \&\&\&\& make install\fR and want to use it in the project. .PP Variables set: .PP .RS .nf CPATH LD\_LIBRARY\_PATH LIBRARY\_PATH MANPATH PATH PKG\_CONFIG\_PATH .fi .RE .PP Example: .PP .RS .nf \&./configure \-\&\-\&prefix=$HOME/rubies/ruby\-\&1.9.3 make \&\&\&\& make install # Then in the .envrc load\_\&prefix \~\&/rubies/ruby\-\&1.9.3 .fi .RE .IP \(bu 2 .PP \fB\fClayout\fR \fItype\fP: A semantic dispatch used to describe common project layouts. .IP \(bu 2 .PP \fB\fClayout go\fR: Sets the GOPATH environment variable to the current directory. .IP \(bu 2 .PP \fB\fClayout node\fR: Adds "$PWD/node\_modules/.bin" to the PATH environment variable. .IP \(bu 2 .PP \fB\fClayout perl\fR: Setup environment variables required by perl's local::lib See \[la]http://search.cpan.org/dist/local-lib/lib/local/lib.pm\[ra] for more details .IP \(bu 2 .PP \fB\fClayout python\fR [\fIpython\_exe\fP]: Creates and loads a virtualenv environment under \fB\fC$PWD/.direnv/python\-$python\_version\fR\&. This forces the installation of any egg into the project's sub\-\&folder. .PP It's possible to specify the python executable if you want to use different versions of python (eg: \fB\fClayout python python3\fR). .PP Note that previously virtualenv was located under \fB\fC$PWD/.direnv/virtualenv\fR and will be re\-used by direnv if it exists. .IP \(bu 2 .PP \fB\fClayout python3\fR: A shortcut for \fB\fClayout python python3\fR .IP \(bu 2 .PP \fB\fClayout ruby\fR: Sets the GEM\_HOME environment variable to \fB\fC$PWD/.direnv/ruby/RUBY\_VERSION\fR\&. 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 \fB\fCbundle exec\fR prefix. .IP \(bu 2 .PP \fB\fCuse\fR \fIprogram\_name\fP [\fIversion\fP]: A semantic command dispatch intended for loading external dependencies into the environment. .PP Example: .PP .RS .nf use\_ruby() { echo "Ruby $1" } use ruby 1.9.3 # output: Ruby 1.9.3 .fi .RE .IP \(bu 2 \fB\fCuse rbenv\fR: Loads rbenv which add the ruby wrappers available on the PATH. .IP \(bu 2 .PP \fB\fCuse nix [...]\fR: Load environment variables from \fB\fCnix\-shell\fR\&. .PP If you have a \fB\fCdefault.nix\fR or \fB\fCshell.nix\fR these will be used by default, but you can also specify packages directly (e.g \fB\fCuse nix \-p ocaml\fR). .PP See \[la]http://nixos.org/nix/manual/#sec-nix-shell\[ra] .IP \(bu 2 .PP \fB\fCuse guix [...]\fR: Load environment variables from \fB\fCguix environment\fR\&. .PP Any arguments given will be passed to guix environment. For example, \fB\fCuse guix hello\fR would setup an environment with the dependencies of the hello package. To create an environment including hello, the \fB\fC\-\-ad\-hoc\fR flag is used \fB\fCuse guix \-\-ad\-hoc hello\fR\&. Other options include \fB\fC\-\-load\fR which allows loading an environment from a file. .PP See \[la]https://www.gnu.org/software/guix/manual/html_node/Invoking-guix-environment.html\[ra] .IP \(bu 2 .PP \fB\fCrvm\fR ...: Should work just like in the shell if you have rvm installed. .IP \(bu 2 .PP \fB\fCuse node\fR: Loads NodeJS version from a \fB\fC\&.node\-\&version\fR or \fB\fC\&.nvmrc\fR file. .PP If you specify a partial NodeJS version (i.e. \fB\fC4.2\fR), a fuzzy match is performed and the highest matching version installed is selected. .PP Example (.envrc): .PP .RS .nf set \-e use node .fi .RE .PP Example (.node\-version): .PP .RS .nf 4.2 .fi .RE .IP \(bu 2 \fB\fCuse node\fR version: Loads specified NodeJS version. .PP Example (.envrc): .PP .RS .nf set \-e use node 4.2.2 .fi .RE .IP \(bu 2 \fB\fCwatch\fR path: Adds a file to direnv's watch\-list. If the file changes direnv will reload the environment on the next prompt. .PP Example (.envrc): .PP .RS .nf watch Gemfile .fi .RE .SH COPYRIGHT .PP Copyright (C) 2014 zimbatm \[la]http://zimbatm.com\[ra] and contributors under the MIT licence. .SH SEE ALSO .PP direnv(1)