ohmyzsh dotenv plugin

1. What does it do?

When working on software projects, it’s easier to handle the environment varialbes with .env file which usually contains any environment varialbes for the application to function as intended.

For example:


There are many packages to allow this to be loaded in the application but I needed this in the shell and look for some good solutions

2. omz with dotenv plugin

I found dotenv plugin for ohmyzsh that can be used with zsh and ohmyzsh environment.

3. How to use

  1. Assuming you’re using zsh and installed ohmyzsh
  2. open .zshrc file
  3. find plugins section and add “dotenv”
    # Which plugins would you like to load?
    # Standard plugins can be found in $ZSH/plugins/
    # Custom plugins may be added to $ZSH_CUSTOM/plugins/
    # Example format: plugins=(rails git textmate ruby lighthouse)
    # Add wisely, as too many plugins slow down shell startup.
      dotenv  # <= add this
  4. Once this is done, when you go to the directory with the .env file in it. It will ask if you want the .env file to be loaded in or not.
    cd my_software_project
    dotenv: found '.env' file. Source it? ([Y]es/[n]o/[a]lways/n[e]ver) Y
  5. If you want to allow it permanently, you can do [a]lways. The file will be stored in $ZSH_CACHE_DIR/dotenv-allowed.list and $ZSH_CACHE_DIR/dotenv-disallowed.list. The default for $ZSH_CACHE_DIR is ~/.oh-my-zsh/cache
    ~ cd .oh-my-zsh/cache
    ~ ls
    completions            dotenv-allowed.list    dotenv-disallowed.list grep-alias
    ~ cat dotenv-allowed.list
Related Post