Skip to content

Commit e051200

Browse files
committed
convert function definition format so typeset works under ksh
1 parent 415ea28 commit e051200

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

docs/en/history.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Release History
33
===============
44

5+
dev
6+
7+
- Change the shell function shell definition syntax so that ksh will
8+
treat typeset-declared variables as local. No kidding.
9+
510
2.8
611

712
- Use VIRTUALENVWRAPPER_VIRTUALENV in `cpvirtualenv` (:bbissue:`104`).

virtualenvwrapper.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ then
6565
VIRTUALENVWRAPPER_ENV_BIN_DIR="Scripts"
6666
fi
6767

68-
virtualenvwrapper_derive_workon_home() {
68+
function virtualenvwrapper_derive_workon_home {
6969
typeset workon_home_dir="$WORKON_HOME"
7070

7171
# Make sure there is a default value for WORKON_HOME.
@@ -103,7 +103,7 @@ virtualenvwrapper_derive_workon_home() {
103103
# create it if it does not
104104
# seperate from creating the files in it because this used to just error
105105
# and maybe other things rely on the dir existing before that happens.
106-
virtualenvwrapper_verify_workon_home () {
106+
function virtualenvwrapper_verify_workon_home {
107107
RC=0
108108
if [ ! -d "$WORKON_HOME/" ]
109109
then
@@ -120,7 +120,7 @@ virtualenvwrapper_verify_workon_home () {
120120
#HOOK_VERBOSE_OPTION="-q"
121121

122122
# Expects 1 argument, the suffix for the new file.
123-
virtualenvwrapper_tempfile () {
123+
function virtualenvwrapper_tempfile {
124124
# Note: the 'X's must come last
125125
typeset suffix=${1:-hook}
126126
typeset file="`\mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX`"
@@ -135,7 +135,7 @@ virtualenvwrapper_tempfile () {
135135
}
136136

137137
# Run the hooks
138-
virtualenvwrapper_run_hook () {
138+
function virtualenvwrapper_run_hook {
139139
typeset hook_script="$(virtualenvwrapper_tempfile ${1}-hook)"
140140
if [ -z "$hook_script" ]
141141
then
@@ -165,7 +165,7 @@ virtualenvwrapper_run_hook () {
165165

166166
# Set up tab completion. (Adapted from Arthur Koziel's version at
167167
# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
168-
virtualenvwrapper_setup_tab_completion () {
168+
function virtualenvwrapper_setup_tab_completion {
169169
if [ -n "$BASH" ] ; then
170170
_virtualenvs () {
171171
local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -202,7 +202,7 @@ virtualenvwrapper_setup_tab_completion () {
202202
}
203203

204204
# Set up virtualenvwrapper properly
205-
virtualenvwrapper_initialize () {
205+
function virtualenvwrapper_initialize {
206206
export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)"
207207

208208
virtualenvwrapper_verify_workon_home -q || return 1
@@ -232,7 +232,7 @@ virtualenvwrapper_initialize () {
232232

233233

234234
# Verify that virtualenv is installed and visible
235-
virtualenvwrapper_verify_virtualenv () {
235+
function virtualenvwrapper_verify_virtualenv {
236236
typeset venv=$(\which "$VIRTUALENVWRAPPER_VIRTUALENV" | (unset GREP_OPTIONS; \grep -v "not found"))
237237
if [ "$venv" = "" ]
238238
then
@@ -248,7 +248,7 @@ virtualenvwrapper_verify_virtualenv () {
248248
}
249249

250250
# Verify that the requested environment exists
251-
virtualenvwrapper_verify_workon_environment () {
251+
function virtualenvwrapper_verify_workon_environment {
252252
typeset env_name="$1"
253253
if [ ! -d "$WORKON_HOME/$env_name" ]
254254
then
@@ -259,7 +259,7 @@ virtualenvwrapper_verify_workon_environment () {
259259
}
260260

261261
# Verify that the active environment exists
262-
virtualenvwrapper_verify_active_environment () {
262+
function virtualenvwrapper_verify_active_environment {
263263
if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]
264264
then
265265
echo "ERROR: no virtualenv active, or active virtualenv is missing" >&2
@@ -273,7 +273,7 @@ virtualenvwrapper_verify_active_environment () {
273273
# Usage: mkvirtualenv [options] ENVNAME
274274
# (where the options are passed directly to virtualenv)
275275
#
276-
mkvirtualenv () {
276+
function mkvirtualenv {
277277
eval "envname=\$$#"
278278
virtualenvwrapper_verify_workon_home || return 1
279279
virtualenvwrapper_verify_virtualenv || return 1
@@ -297,7 +297,7 @@ mkvirtualenv () {
297297
}
298298

299299
# Remove an environment, in the WORKON_HOME.
300-
rmvirtualenv () {
300+
function rmvirtualenv {
301301
typeset env_name="$1"
302302
virtualenvwrapper_verify_workon_home || return 1
303303
if [ "$env_name" = "" ]
@@ -330,7 +330,7 @@ rmvirtualenv () {
330330
}
331331

332332
# List the available environments.
333-
virtualenvwrapper_show_workon_options () {
333+
function virtualenvwrapper_show_workon_options {
334334
virtualenvwrapper_verify_workon_home || return 1
335335
# NOTE: DO NOT use ls here because colorized versions spew control characters
336336
# into the output list.
@@ -340,7 +340,7 @@ virtualenvwrapper_show_workon_options () {
340340
# (\cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
341341
}
342342

343-
_lsvirtualenv_usage () {
343+
function _lsvirtualenv_usage {
344344
echo "lsvirtualenv [-blh]"
345345
echo " -b -- brief mode"
346346
echo " -l -- long mode"
@@ -350,7 +350,7 @@ _lsvirtualenv_usage () {
350350
# List virtual environments
351351
#
352352
# Usage: lsvirtualenv [-l]
353-
lsvirtualenv () {
353+
function lsvirtualenv {
354354

355355
typeset long_mode=true
356356
if command -v "getopts" &> /dev/null
@@ -403,7 +403,7 @@ lsvirtualenv () {
403403
# Show details of a virtualenv
404404
#
405405
# Usage: showvirtualenv [env]
406-
showvirtualenv () {
406+
function showvirtualenv {
407407
typeset env_name="$1"
408408
if [ -z "$env_name" ]
409409
then
@@ -424,7 +424,7 @@ showvirtualenv () {
424424
#
425425
# Usage: workon [environment_name]
426426
#
427-
workon () {
427+
function workon {
428428
typeset env_name="$1"
429429
if [ "$env_name" = "" ]
430430
then
@@ -492,15 +492,15 @@ workon () {
492492

493493

494494
# Prints the Python version string for the current interpreter.
495-
virtualenvwrapper_get_python_version () {
495+
function virtualenvwrapper_get_python_version {
496496
# Uses the Python from the virtualenv because we're trying to
497497
# determine the version installed there so we can build
498498
# up the path to the site-packages directory.
499499
python -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.
500500
}
501501

502502
# Prints the path to the site-packages directory for the current environment.
503-
virtualenvwrapper_get_site_packages_dir () {
503+
function virtualenvwrapper_get_site_packages_dir {
504504
echo "$VIRTUAL_ENV/lib/python`virtualenvwrapper_get_python_version`/site-packages"
505505
}
506506

@@ -515,7 +515,7 @@ virtualenvwrapper_get_site_packages_dir () {
515515
# "virtualenv_path_extensions.pth" inside the virtualenv's
516516
# site-packages directory; if this file does not exist, it will be
517517
# created first.
518-
add2virtualenv () {
518+
function add2virtualenv {
519519

520520
virtualenvwrapper_verify_workon_home || return 1
521521
virtualenvwrapper_verify_active_environment || return 1
@@ -557,23 +557,23 @@ add2virtualenv () {
557557

558558
# Does a ``cd`` to the site-packages directory of the currently-active
559559
# virtualenv.
560-
cdsitepackages () {
560+
function cdsitepackages {
561561
virtualenvwrapper_verify_workon_home || return 1
562562
virtualenvwrapper_verify_active_environment || return 1
563563
typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
564564
\cd "$site_packages"/$1
565565
}
566566

567567
# Does a ``cd`` to the root of the currently-active virtualenv.
568-
cdvirtualenv () {
568+
function cdvirtualenv {
569569
virtualenvwrapper_verify_workon_home || return 1
570570
virtualenvwrapper_verify_active_environment || return 1
571571
\cd $VIRTUAL_ENV/$1
572572
}
573573

574574
# Shows the content of the site-packages directory of the currently-active
575575
# virtualenv
576-
lssitepackages () {
576+
function lssitepackages {
577577
virtualenvwrapper_verify_workon_home || return 1
578578
virtualenvwrapper_verify_active_environment || return 1
579579
typeset site_packages="`virtualenvwrapper_get_site_packages_dir`"
@@ -590,7 +590,7 @@ lssitepackages () {
590590

591591
# Toggles the currently-active virtualenv between having and not having
592592
# access to the global site-packages.
593-
toggleglobalsitepackages () {
593+
function toggleglobalsitepackages {
594594
virtualenvwrapper_verify_workon_home || return 1
595595
virtualenvwrapper_verify_active_environment || return 1
596596
typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt"
@@ -604,7 +604,7 @@ toggleglobalsitepackages () {
604604
}
605605

606606
# Duplicate the named virtualenv to make a new one.
607-
cpvirtualenv() {
607+
function cpvirtualenv {
608608
typeset env_name="$1"
609609
if [ "$env_name" = "" ]
610610
then

0 commit comments

Comments
 (0)