venv.sh
#!/bin/bash
function usage()
{
cat <<EOF
Desc: virtualenv management tool
Usage: linux command alias venv
Options:
[-h|--help] : show this help
[run] : same as virtualenv source
[create] : same as virtualenv newvenv
[exit] : exit current venv
[list] : show all venv
EOF
}
venvdir='/mnt/venv'
case "$1" in
-h|--help)
usage
;;
create)
virtualenv $venvdir/$2 ${@:3}
;;
run)
source $venvdir/$2/bin/activate
;;
exit)
deactivate
;;
list)
ls $venvdir
;;
esac
vim ~/.bashrc
添加 alias venv='source /mnt/script/venv.sh'
生效 source ~/.bashrc
使用
venv -h #查看幫助
venv run xxxx #運行指定虛擬環境
venv exit #退出當前虛擬環境
venv create xxx #創建一個虛擬環境
venv list #查看所有虛擬環境