mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-02-06 02:51:32 +01:00
merge
This commit is contained in:
parent
a8c56f5231
commit
8274156fae
296 changed files with 6279 additions and 3141 deletions
|
|
@ -12,7 +12,7 @@ plugins=(... python)
|
|||
|
||||
| Command | Description |
|
||||
| ---------------- | -------------------------------------------------------------------------------------- |
|
||||
| `py` | Runs `python3` |
|
||||
| `py` | Runs `python3`. Only set if `py` is not installed. |
|
||||
| `ipython` | Runs the appropriate `ipython` version according to the activated virtualenv |
|
||||
| `pyfind` | Finds .py files recursively in the current directory |
|
||||
| `pyclean [dirs]` | Deletes byte-code and cache files from a list of directories or the current one |
|
||||
|
|
@ -22,8 +22,18 @@ plugins=(... python)
|
|||
|
||||
## Virtual environments
|
||||
|
||||
The plugin provides two utilities to manage Python venvs:
|
||||
The plugin provides three utilities to manage Python 3.3+ [venv](https://docs.python.org/3/library/venv.html)
|
||||
virtual environments:
|
||||
|
||||
- `mkv [name]`: make a new virtual environment called `name` (default: `venv`) in current directory.
|
||||
- `mkv [name]`: make a new virtual environment called `name` (default: if set `$PYTHON_VENV_NAME`, else
|
||||
`venv`) in the current directory.
|
||||
|
||||
- `vrun [name]`: activate virtual environment called `name` (default: `venv`) in current directory.
|
||||
- `vrun [name]`: Activate the virtual environment called `name` (default: if set `$PYTHON_VENV_NAME`, else
|
||||
`venv`) in the current directory.
|
||||
|
||||
- `auto_vrun`: Automatically activate the venv virtual environment when entering a directory containing
|
||||
`<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (including
|
||||
subdirectories!).
|
||||
- To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
|
||||
- The default virtual environment name is `venv`. To use a different name, set
|
||||
`export PYTHON_VENV_NAME=<venv-name>`. For example: `export PYTHON_VENV_NAME=".venv"`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
# python command
|
||||
alias py='python3'
|
||||
# set python command if 'py' not installed
|
||||
builtin which py > /dev/null || alias py='python3'
|
||||
|
||||
# Find python file
|
||||
alias pyfind='find . -name "*.py"'
|
||||
|
|
@ -44,18 +44,19 @@ function pyuserpaths() {
|
|||
alias pygrep='grep -nr --include="*.py"'
|
||||
|
||||
# Run proper IPython regarding current virtualenv (if any)
|
||||
alias ipython="python3 -c 'import IPython; IPython.terminal.ipapp.launch_new_instance()'"
|
||||
alias ipython='python3 -c "import IPython, sys; sys.exit(IPython.start_ipython())"'
|
||||
|
||||
# Share local directory as a HTTP server
|
||||
alias pyserver="python3 -m http.server"
|
||||
|
||||
|
||||
## venv utilities
|
||||
: ${PYTHON_VENV_NAME:=venv}
|
||||
|
||||
# Activate a the python virtual environment specified.
|
||||
# If none specified, use 'venv'.
|
||||
# If none specified, use $PYTHON_VENV_NAME, else 'venv'.
|
||||
function vrun() {
|
||||
local name="${1:-venv}"
|
||||
local name="${1:-$PYTHON_VENV_NAME}"
|
||||
local venvpath="${name:P}"
|
||||
|
||||
if [[ ! -d "$venvpath" ]]; then
|
||||
|
|
@ -72,12 +73,26 @@ function vrun() {
|
|||
echo "Activated virtual environment ${name}"
|
||||
}
|
||||
|
||||
# Create a new virtual environment, with default name 'venv'.
|
||||
# Create a new virtual environment using the specified name.
|
||||
# If none specfied, use $PYTHON_VENV_NAME
|
||||
function mkv() {
|
||||
local name="${1:-venv}"
|
||||
local name="${1:-$PYTHON_VENV_NAME}"
|
||||
local venvpath="${name:P}"
|
||||
|
||||
python3 -m venv "${name}" || return
|
||||
echo >&2 "Created venv in '${venvpath}'"
|
||||
vrun "${name}"
|
||||
}
|
||||
|
||||
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
|
||||
# Automatically activate venv when changing dir
|
||||
auto_vrun() {
|
||||
if [[ -f "${PYTHON_VENV_NAME}/bin/activate" ]]; then
|
||||
source "${PYTHON_VENV_NAME}/bin/activate" > /dev/null 2>&1
|
||||
else
|
||||
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
add-zsh-hook chpwd auto_vrun
|
||||
auto_vrun
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue