Skip to content

Instantly share code, notes, and snippets.

@chr15m
Last active February 18, 2025 07:53
Show Gist options
  • Save chr15m/fa077fdd4f496374802e80831c010466 to your computer and use it in GitHub Desktop.
Save chr15m/fa077fdd4f496374802e80831c010466 to your computer and use it in GitHub Desktop.
My Direnv setup for Python & JS isolated development
# You can put these in your .bashrc (or .profile or other shell setup) to setup direnv, pyenv, nvm.
# pyenv setup hook (install it first)
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
# nvm setup hook (install it first)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# direnv setup hook (install it first)
eval "$(direnv hook bash -)"
# Put this in ~/.direnvrc to enable nodejs versions once nvm is installed
use_nodejs() {
NODE_VERSION="$1"
type nvm >/dev/null 2>&1 || . ~/.nvm/nvm.sh
nvm use "$NODE_VERSION"
}
# Example of a .envrc file you can put in a project directory
# Once direnv is set up this file will get run when you change to the directory it's in
# Print something
echo "Hello world from this folder."
# Set an environment variable
export SOME_API_KEY=424242424242
# Source some other script
source mysecrets
# Use a specific Python version with pyenv
layout pyenv 3.6.9
# Use a specific node version (installed with nvm)
use nodejs 22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment