Add oh-my-bash integration for Python development, providing aliases and utilities for everyday workflows including virtual environment management, pip, and project housekeeping. Inspired by the oh-my-zsh python plugin.
Enable the plugin by adding it to your oh-my-bash plugins definition in ~/.bashrc.
plugins=(python)Set these variables before the source "$OSH/oh-my-bash.sh" line in your ~/.bashrc.
| Variable | Default | Description |
|---|---|---|
OMB_PLUGIN_PYTHON_VENV_NAME |
venv |
Default venv directory name used by vrun and mkv |
OMB_PLUGIN_PYTHON_AUTO_VRUN |
(unset) | Set to true to auto-activate venvs on directory change |
| Alias | Command | Description |
|---|---|---|
py |
python3 |
Shorthand for python3 (if py is not already installed) |
pyfind |
find . -name "*.py" |
Find all Python files in current tree |
pygrep |
grep -rn --include="*.py" |
Search inside Python files |
pyserver |
python3 -m http.server |
Serve current directory over HTTP |
| Alias | Command | Description |
|---|---|---|
pipi |
pip install |
Install a package |
pipu |
pip uninstall |
Uninstall a package |
pipup |
pip install --upgrade |
Upgrade a package |
pipr |
pip install -r requirements.txt |
Install from requirements.txt |
pipf |
pip freeze |
Print installed packages |
pipfr |
pip freeze > requirements.txt |
Save installed packages to requirements |
pipls |
pip list |
List installed packages |
pipout |
pip list --outdated |
List outdated packages |
Remove compiled bytecode files and cache directories (__pycache__, .mypy_cache, .pytest_cache) from the given directories, or the current directory if none are specified.
pyclean # clean current directory
pyclean src tests # clean specific directoriesActivate a virtual environment by name. If no name is given, searches for the first existing directory in $OMB_PLUGIN_PYTHON_VENV_NAME, venv, .venv (in that order).
vrun # auto-detect and activate
vrun .venv # activate a specific venvCreate a new virtual environment with python3 -m venv and immediately activate it. Defaults to $OMB_PLUGIN_PYTHON_VENV_NAME.
mkv # create and activate ./venv
mkv .venv # create and activate ./.venvWhen OMB_PLUGIN_PYTHON_AUTO_VRUN=true, the plugin registers a PROMPT_COMMAND hook to automatically activate a virtual environment when you enter a directory that contains one, and deactivate it when you leave. Using PROMPT_COMMAND instead of aliasing cd ensures compatibility with other plugins that also hook into directory changes (e.g. nvm).
# ~/.bashrc (before sourcing oh-my-bash)
OMB_PLUGIN_PYTHON_AUTO_VRUN=true