add va function

This commit is contained in:
TheK4n 2021-10-01 02:58:11 +03:00
parent 7b0cbb219d
commit 5a367f3f09
2 changed files with 27 additions and 4 deletions

View File

@ -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'

View File

@ -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
}