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           #查看所有虚拟环境

冰河
1 声望0 粉丝

引用和评论

0 条评论