Skip to content

Commit

Permalink
Pre- and post-activation hooks.
Browse files Browse the repository at this point in the history
The activate and deactivate scripts will call
~/.hsenv/bin/(pre|post)-(de|)activate at the appropriate times.
  • Loading branch information
psagers committed Nov 26, 2013
1 parent 18e28ec commit 6c93b39
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ hsenv --name=<ENVIRONMENT_NAME>

This will make hsenv generate a folder of the form `.hsenv_<ENVIRONMENT_NAME>`.

Customization
-------------

If you want to customize activation and deactivation, create one or more of the
following files in ~/.hsenv/bin/: pre-activate, post-activate, pre-deactivate,
post-deactivate. These shell scripts will be sourced automatically by the main
activation script.

Advanced usage
--------------
Here's the most advanced usage of hsenv. Let's say you want to:
Expand Down
16 changes: 16 additions & 0 deletions skeletons/activate
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ if [ -n "${HSENV}" ]; then
return 1
fi

# Source a user script.
hsenv_bin() {
if [ -f ~/.hsenv/bin/$1 ]; then
. ~/.hsenv/bin/$1
fi
}

export HSENV="<HSENV>"
export HSENV_NAME="<HSENV_NAME>"

Expand All @@ -19,6 +26,8 @@ echo "Use regular Haskell tools (ghc, ghci, ghc-pkg, cabal) to manage your Haske
echo ""
echo "To exit from this virtual environment, enter command 'deactivate_hsenv'."

hsenv_bin pre-activate

HSENV_PATH_BACKUP="$PATH"

if <MODIFY_PS1>; then
Expand All @@ -29,6 +38,8 @@ deactivate_hsenv() {
echo "Deactivating ${HSENV_NAME} Virtual Haskell Environment (at ${HSENV})."
echo "Restoring previous environment settings."

hsenv_bin pre-deactivate

export PATH="$HSENV_PATH_BACKUP"
unset -v HSENV_PATH_BACKUP

Expand All @@ -37,6 +48,8 @@ deactivate_hsenv() {
unset -v HSENV_PS1_BACKUP
fi

hsenv_bin post-deactivate

unset -v PACKAGE_DB_FOR_CABAL
unset -v PACKAGE_DB_FOR_GHC_PKG
unset -v PACKAGE_DB_FOR_GHC
Expand All @@ -45,6 +58,7 @@ deactivate_hsenv() {
unset -v HSENV_NAME
unset -v HASKELL_PACKAGE_SANDBOX
unset -f deactivate_hsenv
unset -f hsenv_bin

if [ -n "$BASH" -o -n "$ZSH_VERSION" ]; then
hash -r
Expand Down Expand Up @@ -117,3 +131,5 @@ unset -v GHC_PACKAGE_PATH_REPLACEMENT
if [ -n "$BASH" -o -n "$ZSH_VERSION" ]; then
hash -r
fi

hsenv_bin post-activate

0 comments on commit 6c93b39

Please sign in to comment.