aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2015-05-11 11:48:39 +0200
committerDuncaen <mail@duncano.de>2015-05-11 11:48:39 +0200
commit9de285f8d88bf92037845396fe072ca5d4ba0d56 (patch)
treefeb630cb71e5cea002604b470f77a0ff668749ff
parent642e195708a3dd42c910b0063275b287d06f2b18 (diff)
downloaddotfiles-9de285f8d88bf92037845396fe072ca5d4ba0d56.tar.gz
venv: add bin folder and move venv to it
-rwxr-xr-xbin/venv73
-rwxr-xr-xinstall.sh3
2 files changed, 76 insertions, 0 deletions
diff --git a/bin/venv b/bin/venv
new file mode 100755
index 0000000..7a76d41
--- /dev/null
+++ b/bin/venv
@@ -0,0 +1,73 @@
+#!/bin/mksh
+
+readonly PROGNAME=$(basename $0)
+
+function venv_create {
+ if [[ ! -d $VENV_PATH/$1 ]]; then
+ mkdir -pv $VENV_PATH/$1
+ fi
+ ${VENV_CMD} $VENV_PATH/$1
+}
+
+function venv_delete {
+ if [[ -d $VENV_PATH/$1 ]]; then
+ rm -rfv $VENV_PATH/$1
+ fi
+}
+
+function venv_activate {
+ if [[ ! -d $VENV_PATH/$1 ]]; then
+ echo "venv: $1 not found"
+ exit
+ fi
+ export _ORIG_PATH="$PATH"
+ export VIRTUAL_ENV="$VENV_PATH/$1"
+ export PATH="$VIRTUAL_ENV/bin:$PATH"
+ if [[ -n $PYTHONHOME ]]; then
+ export _ORIG_PYTHONHOME="$PYTHONHOME"
+ unset PYTHONHOME
+ fi
+}
+
+function venv_deactivate {
+ if [[ -z $VIRTUAL_ENV ]]; then
+ echo "venv: not active"
+ exit
+ fi
+ if [[ -n $_ORIG_PATH ]]; then
+ export PATH="$_ORIG_PATH"
+ unset _ORIG_PATH
+ fi
+ if [[ -n $_ORIG_PYTHONHOME ]]; then
+ export PYTHONHOME="$_ORIG_PYTHONHOME"
+ unset _ORIG_PYTHONHOME
+ fi
+}
+
+function usage {
+ cat <<_EOF
+ Usage: $PROGNAME <command> [<args>]
+
+ Commands:
+ create <name>
+ delete <name>
+ activate <name>
+ deactivate
+_EOF
+}
+
+: ${CONFIG_FILE:=~/.venv/config}
+: ${VENV_PATH:=~/.venv}
+: ${VENV_CMD:=virtualenv-2.7}
+
+if [ -r ${CONFIG_FILE} ]; then
+ . $CONFIG_FILE
+fi
+
+case "$1" in
+ cr*) venv_create $2;;
+ del*) venv_delete $2;;
+ ac*) venv_activate $2;;
+ dea*) venv_deactivate;;
+ *) usage;;
+esac
diff --git a/install.sh b/install.sh
index ba2b40d..2bded0c 100755
--- a/install.sh
+++ b/install.sh
@@ -24,5 +24,8 @@ ln -sfv $dotfiles/inputrc /home/$user/.inputrc
rm -v /home/$user/.gitconfig
ln -sfv $dotfiles/gitconfig /home/$user/.gitconfig
+rm -v /home/$user/bin
+ln -sfv $dotfiles/bin /home/$user/bin
+
# install plugins
# vim +PlugInstall +qall