6 releases

Uses old Rust 2015

0.1.5 Jul 8, 2018
0.1.4 Jul 8, 2018

#16 in #developer-tools

WTFPL license

99KB
302 lines

fbenv Crates

ATTENTION: Early alpha!

Why should I use this tool?

It is direnv but for a more global scope. So if you want to have directory based environments, use direnv, but if you want to have an environment for the current shell, you can use fbenv.

Prerequisites

  • Installation via cargo install fbenv
  • Optionally install fzf helping you with the zsh completion

Usage

  • Add a file fbenv.toml to your home directory:
[environment1]
SOME_VAR = "foo"

[environment2]
SOME_VAR = "bar"
  • Manual usage:
    • fbenv ls to show the keys of all your environments
    • fbenv get environment1 to get an output like:
      export FBENV=environment1;
      
      export SOME_VAR="foo";
      
    • Switching to a given environment can be done manually:
      • Evaluate the output of fbenv:
        eval $(fbenv get environment1)
        
      • printenv | grep SOME_VAR should yield "foo"
    • or via zsh completion

Known limitations

  • Only TOML tables are currently supported as of now:
SOME_VAR = "blubb"

[environment1]
SOME_OTHER_VAR = "bla"

will ignore the variable SOME_VAR!

ZSH completion

  • Install fzf for adding extra sugar to your workflow :)
  • Add this to your zsh config:
if [[ -x "$(command -v fbenv)" ]];
then
  if [[ -x "$(command -v fzf)" ]];
  then
    eval $(fbenv print-zsh-setup --with-fzf 2>/dev/null);
  else
    eval $(fbenv print-zsh-setup 2>/dev/null);
  fi;
fi;
  • Now you are able to switch environments via switch-env command

grml ZSH

When you are lucky to use the grml zsh config, you can add the current environment to your prompt:

function fb_env_prompt () {
  if [ -n "$FBENV" ];
  then
    REPLY="fbenv ~ $FBENV "
  else
    REPLY=""
  fi;
}

grml_theme_add_token longpath '%60<..<%~%<<' '%B' '%b
grml_theme_add_token magentahost '%m' '%F{magenta}' '%f'
grml_theme_add_token greenuser '%n' '%F{green}' '%f'
grml_theme_add_token gtprompt "»"
grml_theme_add_token space ' '
grml_theme_add_token fb-env -f fb_env_prompt '%F{cyan}' '%f'

zstyle ':prompt:grml:left:setup' items date space time fb-env change-root greenuser at magentahost newline gtprompt space

This will look like this:

2018-07-08 22:46:13 fbenv ~ environment1 user@host
» 

Dependencies

~1–10MB
~71K SLoC