GetStream / vg

Virtualgo: Easy and powerful workspace based development for go
MIT License
1.32k stars 45 forks source link

Is it possible to auto deactivate when `cd` out of the directory? #24

Closed roxma closed 5 years ago

JelteF commented 6 years ago

At the moment it's not part of the functionality. But it should be relatively easy to add. Relevant code is here:

Basically you could add if no .virtualgo file is found and a workspace is active, run vg deactivate. One important thing though is probably to keep tracked if the current workspace was auto activated or not. Because if it was activated manually you wouldn't want to deactivate it when moving somewhere else.

10xjs commented 6 years ago

Current solution working for me in ZSH:

__vg_auto_deactivate() {
  local activation_root
  activation_root=$PWD

  if [ "$VIRTUALGO" = "" ]; then
    return
  fi

  while [ -s "$activation_root" ]; do
    if [ -f "$activation_root/.virtualgo" ]; then
      return
    fi
    # this strips the last path component from the path.
    activation_root=$(echo "$activation_root" | sed 's|/[^/]*$||')
  done

  vg deactivate
}

chpwd_functions=(${chpwd_functions[@]} "__vg_auto_deactivate")
roxma commented 5 years ago

I'm more comfortable with plugins like direnv for this purpose. I've even created another one envrc-rs.

This is not an issue for me anymore. Closing.