almnck/bin/activate-all
2023-12-13 00:48:09 -08:00

48 lines
1.1 KiB
Text
Executable file

#!/bin/echo "source me, don't run me"
###
# activate-all - shell environment for almanack
###
# Note, you should source these, not execute this script
# This stuff has been tried on zsh, but should work on bash.
###
if [ -n "$BASH_VERSION" ]; then
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
elif [ -n "$ZSH_VERSION" ]; then
script_dir=$(cd "$(dirname "$0")" && pwd)
else
echo "Unsupported shell."
exit 1
fi
declare -x ALMANACK_ROOT=$(dirname $script_dir)
# Check for the existence of the venv directory
if [ ! -d "$ALMANACK_ROOT/venv" ]; then
echo "The virtual environment directory does not exist. Please run:"
echo "python -m venv $ALMANACK_ROOT/venv --prompt almnck"
return 1 2>/dev/null || exit 1
fi
. $ALMANACK_ROOT/venv/bin/activate
PATH=$ALMANACK_ROOT/bin:$PATH
# Default to going to the root of almanack
cd() {
if [[ $# -eq 0 ]]; then
builtin cd $ALMANACK_ROOT || builtin cd
else
builtin cd "$@"
fi
}
# Almanack utilities
a-pass() {
PASSWORD_STORE_DIR=$ALMANACK_ROOT/secrets/ pass $*
}
a-deactivate() {
deactivate
unset -f cd
}