Hacker News new | ask | show | jobs
by luord 3282 days ago
Something that I added to my bash profile is this simple `cd` override that triggers `workon` from `virtualenvwrapper` if the folder I'm accessing has a `virtualenv` with the same name.

    cd()
    {
      command cd "$@"
      [[ "$OLDPWD" == "$HOME"/Work/* && ! -z "$VIRTUAL_ENV" && "$OLDPWD" == *"${VIRTUAL_ENV##*/}"* && "$PWD" != *"${VIRTUAL_ENV##*/}"* ]] && deactivate
      [[ -z "$VIRTUAL_ENV" && "$PWD" == "$HOME"/Work/* ]] && next="$(sed -e "s/^.*Work\///" -e "s/\/.*$//" <<< "$PWD")" && [[ -d "$WORKON_HOME"/"$next" ]] && workon "$next" && unset next
    }
Yes, too many one-liners and short-circuits are usually a no-no, but it's not like anyone else is ever going to use this and I like these shortcuts.