Shell Productivity
Aliases, shell functions, and history tricks for Python developers living in bash/zsh - faster git, uv, pytest, and SSH without memorizing every flag.
Recipe
# ~/.bashrc or ~/.zshrc
alias gs='git status -sb'
alias uvr='uv run'
alias pyt='uv run pytest -q'
gco() { git checkout "$@"; }When to reach for this:
- Repeated daily command sequences
- Standardizing team shortcuts in onboarding doc
- Recovering last week's
curl | jqpipeline from history - Fuzzy picking git branch before rebase
Working Example
# ~/.zshrc excerpts for Python monorepo
export PATH="$HOME/.local/bin:$PATH"
alias uvs='uv sync'
alias uvt='uv run pytest -q'
alias ruffc='uv run ruff check .'
alias rufff='uv run ruff format .'
# Smoke function committed pattern - promote to bin/smoke.sh when shared
billing-smoke() {
set -euo pipefail
curl -sf http://localhost:8000/health
curl -sf http://localhost:8000/ready
echo "smoke ok"
}
# fzf git checkout (requires fzf)
alias gcb='git branch | fzf | xargs git checkout'What this demonstrates:
- Short aliases for high-frequency uv/ruff/pytest
- Function with
set -euo pipefailfor smoke tests - fzf integration for branch picking
- PATH includes pipx/uv tools
Deep Dive
How It Works
- Alias - Simple string substitution; no arguments logic.
- Function - Bash/zsh function supports args and local vars.
- History -
HISTSIZE,HISTFILESIZE,histappendfor persistence. - fzf - Fuzzy finder over any list (files, branches, history).
Productivity Tools
| Tool | Purpose |
|---|---|
fzf | Fuzzy select files, branches |
direnv | Auto-load .envrc per project dir |
zoxide | z billing jump to frecent dir |
starship | Cross-shell prompt with venv indicator |
Python Notes
# Show active venv in prompt - starship python module or:
export PS1='($(basename $VIRTUAL_ENV)) \u@\h:\w$ '
# History search backward for rg
bind '"\C-r": reverse-search-history' # bash defaultGotchas
- Alias overriding binaries -
alias ls='ls --color'OK; maskingpythondangerous. Fix: avoid alias onpython,rm,git push. - Functions without pipefail - Silent partial failure. Fix:
set -euo pipefailat top. - Secrets in history -
curl -H "Authorization: Bearer ..."saved. Fix:HISTIGNOREpattern or space-prefix +HISTCONTROL=ignorespace. - Copying personal aliases to prod servers - Noise on shared accounts. Fix: minimal aliases on prod; scripts in
/opt/app/bin. - Zsh vs bash in CI docs - Onboarding shows bash; dev uses zsh. Fix: document both or standardize.
- Huge .bashrc slows SSH - Lazy-load nvm-style plugins. Fix: split optional
~/.bashrc.d/.
Alternatives
| Alternative | Use When | Don't Use When |
|---|---|---|
Makefile make test | Team wants one interface | Windows-only devs without make |
just runner | Rich command recipes | Zero extra deps policy |
| IDE tasks | GUI-centric devs | SSH-only operators |
| Dedicated CLI (Typer) | Complex subcommands | Simple alias enough |
FAQs
bash or zsh for Python dev?
Both fine on macOS/Linux - zsh default on macOS; ensure scripts are bash-compatible for CI.
direnv with uv?
.envrc with layout uv or source .venv/bin/activate auto on cd.
Share team aliases?
Document in repo docs/shell.md - do not force dotfiles via repo without opt-in.
history timestamp?
export HISTTIMEFORMAT='%F %T ' in bash for when you ran that migration command.
global gitignore?
git config --global core.excludesfile ~/.gitignore_global for .DS_Store, .idea.
Ctrl-r not working?
Check bindkey in zsh; install fzf keybindings package.
Tab completion uv?
uv generate-shell-completion zsh >> ~/.zshrc completion dir.
Alias in non-interactive SSH?
Aliases often disabled - use full commands in cron/systemd.
Oh My Zsh slowdown?
Disable unused plugins; starship alone is lighter.
When alias becomes script?
When it has args, error handling, or is shared by team - move to bin/ with tests.
Related
- Python-in-the-Shell - uv and venv
- Git Configuration - git aliases
- Environment Setup Checklist - shell setup
- Robust Scripts - bash discipline
Stack versions: This page was written for Python 3.14.0 (stable 3.14, maintenance 3.13), FastAPI 0.115+, Django 5.2, Flask 3.1, Pydantic 2, PyTorch 2.6+, pandas 2.2+, Polars 1.x, ruff 0.9+, and uv 0.6+.