Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
02eb548d
Unverified
Commit
02eb548d
authored
4 years ago
by
Marijan Smetko
Committed by
Marc Cornellà
3 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(python): add utilities to manage simple virtual environments (#9776)
Closes #9776
parent
3e2676f7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
README.md
plugins/python/README.md
+9
-0
python.plugin.zsh
plugins/python/python.plugin.zsh
+33
-0
No files found.
plugins/python/README.md
View file @
02eb548d
...
...
@@ -10,6 +10,7 @@ plugins=(... python)
## Aliases
<<<<<<< HEAD
| Command | Description |
| ---------------- | ------------------------------------------------------------------------------------- |
|
`py`
| Runs
`python`
|
...
...
@@ -19,3 +20,11 @@ plugins=(... python)
|
`pygrep <text>`
| Looks for
`text`
in .py files |
|
`pyuserpaths`
| Add --user site-packages to PYTHONPATH, for all installed python versions. |
|
`pyserver`
| Starts an http.server on the current directory. Use
`--directory`
for a different one |
## Virtual environments
The plugin provides two utilities to manage Python venvs:
-
`mkv [name]`
: make a new virtual environment called
`name`
(default:
`venv`
) in current directory.
-
`vrun [name]`
: activate virtual environment called
`name`
(default:
`venv`
) in current directory.
This diff is collapsed.
Click to expand it.
plugins/python/python.plugin.zsh
View file @
02eb548d
...
...
@@ -51,3 +51,36 @@ alias ipython="python -c 'import IPython; IPython.terminal.ipapp.launch_new_inst
# Share local directory as a HTTP server
alias
pyserver
=
"python -m http.server"
## venv utilities
# Activate a the python virtual environment specified.
# If none specified, use 'venv'.
function
vrun
()
{
local
name
=
"
${
1
:-
venv
}
"
local
venvpath
=
"
${
name
:P
}
"
if
[[
!
-d
"
$venvpath
"
]]
;
then
echo
>
&2
"Error: no such venv in current directory:
$name
"
return
1
fi
if
[[
!
-f
"
${
venvpath
}
/bin/activate"
]]
;
then
echo
>
&2
"Error: '
${
name
}
' is not a proper virtual environment"
return
1
fi
.
"
${
venvpath
}
/bin/activate"
||
return
$?
echo
"Activated virtual environment
${
name
}
"
}
# Create a new virtual environment, with default name 'venv'.
function
mkv
()
{
local
name
=
"
${
1
:-
venv
}
"
local
venvpath
=
"
${
name
:P
}
"
python3
-m
venv
"
${
name
}
"
||
return
echo
>
&2
"Created venv in '
${
venvpath
}
'"
vrun
"
${
name
}
"
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment