diff --git a/.bash_aliases b/.bash_aliases index 6e04a6d..d845c6c 100644 --- a/.bash_aliases +++ b/.bash_aliases @@ -26,7 +26,7 @@ alias ...='cd ../..' alias .3='cd ../../..' alias path='echo -e ${PATH//:/\\n}' - +alias aliases='alias | cut -d " " -f 1-' # shorts alias c='clear' @@ -78,8 +78,10 @@ alias music='mplayer -shuffle ~/Music/*' # python + +# initializes first ./*/*/activate +# alias va='source "$(find -P . -maxdepth 3 -mindepth 3 -type f -name activate | sort | head -n 1)" &>/dev/null || echo "error: virtual env not found, use python3 -m virtualenv venv" >&2' alias ve='python3 -m virtualenv venv' -alias va='. venv/bin/activate' alias vd='deactivate' diff --git a/.bash_functions b/.bash_functions index 2d16418..63aae7f 100644 --- a/.bash_functions +++ b/.bash_functions @@ -37,7 +37,7 @@ workon() { return 1 # exit code fi - . /opt/pythonenv/"${1}"/bin/activate + source /opt/pythonenv/"${1}"/bin/activate } @@ -46,8 +46,29 @@ cl() { DIR="$*" if [ $# -lt 1 ]; then - DIR=$HOME + DIR="$HOME" fi cd "${DIR}" && ls -F --color=auto } + + +va() { + local activate_venv + + if [ -f "./venv/bin/activate" ]; then + source "./venv/bin/activate" + return 0 + fi + + activate_venv="$(find -P . -maxdepth 3 -mindepth 3 -type f -name activate | sort | head -n 1)" + + if [ -n "$activate_venv" ]; then + source "$activate_venv" + return 0 + else + echo "error: virtual environment not found, use python3 -m virtualenv venv" >&2 + return 1 + fi +} +