Will & Skill Developers

Will & Skill Developers


Thoughts, snippets and ideas from the team at Will & Skill AB, Stockholm.

Faisal Mahmud
Author

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Share


Install direnv on Ubuntu 16.04 in 1 min

Faisal MahmudFaisal Mahmud

At Will & Skill we care deeply about using the right tools to optimize our workflow. If we can shave off a few seconds here and there we can save a lot of time in the long run.

direnv is a small but nifty tool that optimizes the task of switching to the right virtualenv

1. Install direnv

sudo apt-get update  
sudo apt-get install direnv  

2. Add the snippet below in Your .bashrc/.zshrc

show_virtual_env() {  
  if [ -n "$VIRTUAL_ENV" ]; then
    echo "($(basename $VIRTUAL_ENV))"
  fi
}

PS1='$(show_virtual_env)'$PS1

# direnv
eval "$(direnv hook bash)"  

3. Add .direnvrc to your home folder

Copy this snippet to the .direnv that You just created

layout_virtualenv() {  
  local venv_path="$1"
  source ${venv_path}/bin/activate
}

4. Add .envrc in your project folder for instance in /home/faisal/myproject and copy the snippet below into the file

layout virtualenv ~/myproject/myproject-env  

That's it! Happy coding.

Faisal Mahmud
Author

Faisal Mahmud

“The mind is not a vessel to be filled, but a fire to be kindled.” ― Plutarch

Comments