7878 export VIRTUALENVWRAPPER_PROJECT_FILENAME=" .project"
7979fi
8080
81+ # Remember where we are running from.
82+ if [ -z " $VIRTUALENVWRAPPER_SCRIPT " ]
83+ then
84+ export VIRTUALENVWRAPPER_SCRIPT=" $0 "
85+ fi
86+
8187# Portable shell scripting is hard, let's go shopping.
8288#
8389# People insist on aliasing commands like 'cd', either with a real
@@ -375,6 +381,7 @@ function virtualenvwrapper_mkvirtualenv_help {
375381# Usage: mkvirtualenv [options] ENVNAME
376382# (where the options are passed directly to virtualenv)
377383#
384+ # :help:mkvirtualenv: Create a new virtualenv in $WORKON_HOME
378385function mkvirtualenv {
379386 typeset -a in_args
380387 typeset -a out_args
@@ -491,7 +498,7 @@ function mkvirtualenv {
491498 virtualenvwrapper_run_hook " post_mkvirtualenv"
492499}
493500
494- # Remove an environment, in the WORKON_HOME.
501+ # :help:rmvirtualenv: Remove a virtualenv
495502function rmvirtualenv {
496503 virtualenvwrapper_verify_workon_home || return 1
497504 if [ ${#@ } = 0 ]
@@ -558,9 +565,7 @@ function _lsvirtualenv_usage {
558565 echo " -h -- this help message"
559566}
560567
561- # List virtual environments
562- #
563- # Usage: lsvirtualenv [-l]
568+ # :help:lsvirtualenv: list virtualenvs
564569function lsvirtualenv {
565570
566571 typeset long_mode=true
@@ -608,9 +613,7 @@ function lsvirtualenv {
608613 fi
609614}
610615
611- # Show details of a virtualenv
612- #
613- # Usage: showvirtualenv [env]
616+ # :help:showvirtualenv: show details of a single virtualenv
614617function showvirtualenv {
615618 typeset env_name=" $1 "
616619 if [ -z " $env_name " ]
@@ -646,10 +649,7 @@ function virtualenvwrapper_workon_help {
646649 echo " "
647650}
648651
649- # List or change working virtual environments
650- #
651- # Usage: workon [environment_name]
652- #
652+ # :help:workon: list or change working virtualenvs
653653function workon {
654654 in_args=( " $@ " )
655655
@@ -765,6 +765,8 @@ function virtualenvwrapper_get_site_packages_dir {
765765# "virtualenv_path_extensions.pth" inside the virtualenv's
766766# site-packages directory; if this file does not exist, it will be
767767# created first.
768+ #
769+ # :help:add2virtualenv: add directory to the import path
768770function add2virtualenv {
769771 virtualenvwrapper_verify_workon_home || return 1
770772 virtualenvwrapper_verify_active_environment || return 1
@@ -829,6 +831,7 @@ function add2virtualenv {
829831
830832# Does a ``cd`` to the site-packages directory of the currently-active
831833# virtualenv.
834+ # :help:cdsitepackages: change to the site-packages directory
832835function cdsitepackages {
833836 virtualenvwrapper_verify_workon_home || return 1
834837 virtualenvwrapper_verify_active_environment || return 1
@@ -837,6 +840,7 @@ function cdsitepackages {
837840}
838841
839842# Does a ``cd`` to the root of the currently-active virtualenv.
843+ # :help:cdvirtualenv: change to the $VIRTUAL_ENV directory
840844function cdvirtualenv {
841845 virtualenvwrapper_verify_workon_home || return 1
842846 virtualenvwrapper_verify_active_environment || return 1
@@ -845,6 +849,7 @@ function cdvirtualenv {
845849
846850# Shows the content of the site-packages directory of the currently-active
847851# virtualenv
852+ # :help:lssitepackages: list contents of the site-packages directory
848853function lssitepackages {
849854 virtualenvwrapper_verify_workon_home || return 1
850855 virtualenvwrapper_verify_active_environment || return 1
@@ -862,6 +867,7 @@ function lssitepackages {
862867
863868# Toggles the currently-active virtualenv between having and not having
864869# access to the global site-packages.
870+ # :help:toggleglobalsitepackages: turn access to global site-packages on/off
865871function toggleglobalsitepackages {
866872 virtualenvwrapper_verify_workon_home || return 1
867873 virtualenvwrapper_verify_active_environment || return 1
@@ -875,7 +881,7 @@ function toggleglobalsitepackages {
875881 fi
876882}
877883
878- # Duplicate the named virtualenv to make a new one.
884+ # :help:cpvirtualenv: duplicate the named virtualenv to make a new one
879885function cpvirtualenv {
880886 virtualenvwrapper_verify_workon_home || return 1
881887 virtualenvwrapper_verify_virtualenv_clone || return 1
@@ -968,6 +974,7 @@ function virtualenvwrapper_verify_project_home {
968974# Given a virtualenv directory and a project directory,
969975# set the virtualenv up to be associated with the
970976# project
977+ # :help:setvirtualenvproject: associate a project directory with a virtualenv
971978function setvirtualenvproject {
972979 typeset venv=" $1 "
973980 typeset prj=" $2 "
@@ -1024,7 +1031,7 @@ function virtualenvwrapper_mkproject_help {
10241031 " $VIRTUALENVWRAPPER_PYTHON " -c ' from virtualenvwrapper.hook_loader import main; main()' -l project.template
10251032}
10261033
1027- # Create a new project directory and its associated virtualenv.
1034+ # :help:mkproject: create a new project directory and its associated virtualenv
10281035function mkproject {
10291036 typeset -a in_args
10301037 typeset -a out_args
@@ -1109,7 +1116,7 @@ function mkproject {
11091116 virtualenvwrapper_run_hook " project.post_mkproject"
11101117}
11111118
1112- # Change directory to the active project
1119+ # :help:cdproject: change directory to the active project
11131120function cdproject {
11141121 virtualenvwrapper_verify_workon_home || return 1
11151122 virtualenvwrapper_verify_active_environment || return 1
@@ -1135,6 +1142,7 @@ function cdproject {
11351142#
11361143# Originally part of virtualenvwrapper.tmpenv plugin
11371144#
1145+ # :help:mktmpenv: create a temporary virtualenv
11381146function mktmpenv {
11391147 typeset tmpenvname
11401148 typeset RC
@@ -1175,6 +1183,7 @@ EOF
11751183#
11761184# Remove all installed packages from the env
11771185#
1186+ # :help:wipeenv: remove all packages installed in the current virtualenv
11781187function wipeenv {
11791188 virtualenvwrapper_verify_workon_home || return 1
11801189 virtualenvwrapper_verify_active_environment || return 1
@@ -1196,6 +1205,7 @@ function wipeenv {
11961205#
11971206# Run a command in each virtualenv
11981207#
1208+ # :help:allvirtualenv: run a command in all virtualenvs
11991209function allvirtualenv {
12001210 virtualenvwrapper_verify_workon_home || return 1
12011211 typeset d
@@ -1214,6 +1224,7 @@ function allvirtualenv {
12141224 done
12151225}
12161226
1227+ # :help:virtualenvwrapper: show this help message
12171228function virtualenvwrapper {
12181229 cat << EOF
12191230
@@ -1229,43 +1240,14 @@ For more information please refer to the documentation:
12291240
12301241Commands available:
12311242
1232- add2virtualenv: Adds the specified directories to the Python
1233- path for the currently-active virtualenv.
1234- allvirtualenv: Run a command in all virtualenvs under
1235- \$ WORKON_HOME
1236- cdproject: Change the current working directory to the
1237- one specified as the project directory for
1238- the active virtualenv.
1239- cdsitepackages: Change the current working directory to the
1240- site-packages for \$ VIRTUAL_ENV.
1241- cdvirtualenv: Change the current working directory to
1242- \$ VIRTUAL_ENV
1243- cpvirtualenv: Duplicate an existing virtualenv environment.
1244- deactivate: Switch from a virtual environment to the
1245- system-installed version of Python
1246- lssitepackages: Shows the content of the site-packages directory
1247- of the currently-active virtualenv
1248- lsvirtualenv: List all virtual environments, use -h for more
1249- info
1250- mkproject: Create a new virtualenv in the \$ WORKON_HOME and
1251- project directory in \$ PROJECT_HOME
1252- mktmpenv: Create a new temporary virtualenv in the
1253- \$ WORKON_HOME directory with a generated name
1254- mkvirtualenv: Create a new environment, in the \$ WORKON_HOME,
1255- use -h for more info.
1256- rmvirtualenv: Remove an environment
1257- setvirtualenvproject: Bind an existing virtualenv to an existing
1258- project.
1259- showvirtualenv: Show the details for a single virtualenv
1260- toggleglobalsitepackages: Controls whether the active virtualenv will
1261- access the packages in the global
1262- Python site-packages directory.
1263- virtualenvwrapper: Prints this help message
1264- wipeenv: Remove all of the installed third-party
1265- packages in the current virtualenv.
1266- workon: List or change working virtual environments
1267-
12681243EOF
1244+
1245+ typeset helpmarker=" #:help:"
1246+ cat " $VIRTUALENVWRAPPER_SCRIPT " \
1247+ | grep " ^$helpmarker " \
1248+ | sed -e " s/^$helpmarker / /g" \
1249+ | sort \
1250+ | sed -e ' s/$/\' $' \n /g'
12691251}
12701252
12711253#
0 commit comments