1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-01-07 21:18:01 +08:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Daniel Isnardo
5628cefa32
Merge e7bc587a0b into 72acd2ca90 2025-12-08 16:58:00 +01:00
Mohaiminus Sakib
72acd2ca90
feat(uv): add more useful aliases (#13462)
Co-authored-by: Mohaiminus Sakib <roddur093@gmail.com>
Co-authored-by: Marc Cornellà <marc@mcornella.com>
2025-12-08 16:57:50 +01:00
Daniel Isnardo
e7bc587a0b This plugin provides completion for claude 2025-11-28 19:38:58 -05:00
5 changed files with 318 additions and 18 deletions

28
plugins/claude/README.md Normal file
View File

@ -0,0 +1,28 @@
## Zsh completion function `_claude`
This version aims to be:
- Pure zsh (no jq, sed, awk, etc.).
- Generous with known subcommands and options from public Claude Code CLI docs/cheatsheets.[2][3]
- Extensible via simple arrays.
## How to enable in Oh My Zsh
1. In `~/.zshrc`, add `claude` to plugins:
```zsh
plugins=(
git
claude
)
```
2. Reload your shell:
```zsh
exec zsh
```
Now `claude <TAB>` will complete subcommands and flags on macOS, Linux, *BSD, and WSL2, because it relies only on zshs built-in completion engine and standard shell constructs.
***

249
plugins/claude/_claude Normal file
View File

@ -0,0 +1,249 @@
# Zsh completion for the `claude` CLI.
# Guard multiple loads
(( $+functions[_claude] )) && return 0
_claude() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
'(-h --help)'{-h,--help}'[Show help information]' \
'(-V --version)'{-V,--version}'[Show CLI version]' \
'(-v --verbose)'{-v,--verbose}'[Increase verbosity]' \
'(-q --quiet)'{-q,--quiet}'[Reduce output]' \
'(-c --continue)'{-c,--continue}'[Continue most recent conversation]' \
'(-p --print)'{-p,--print}'[Print-only mode (no streaming)]' \
'(-y --yes)'{-y,--yes}'[Assume yes for all prompts]' \
'(-n --no-color)'{-n,--no-color}'[Disable colored output]' \
'(-C --config)'{-C,--config}'[Specify config file]:config file:_files' \
'(-o --output)'{-o,--output}'[Write response to file]:output file:_files' \
'(-m --model)'{-m,--model}'[Select Claude model]:model name:->model' \
'(-s --session)'{-s,--session}'[Use or resume session by ID]:session id: ' \
'(-i --input)'{-i,--input}'[Send file(s) as input]:input file(s):_files' \
'(-I --stdin)'{-I,--stdin}'[Read prompt from stdin]' \
'(-d --directory)'{-d,--directory}'[Working directory for context]:directory:_files -/' \
'(-)'{-,-\-}'[End of options]' \
'1:subcommand:->subcmd' \
'*::args:->args' && return 0
case $state in
model)
# Common Claude models easy to tweak/extend.
local -a models
models=(
'claude-4.1:General-purpose, high capability'
'claude-4.1-sonnet:Fast, strong reasoning'
'claude-4.1-haiku:Cheaper, very fast'
'claude-3.7-sonnet:Previous-gen balanced model'
)
_describe -t models 'Claude model' models
return
;;
subcmd)
_claude_subcommands
return
;;
args)
_claude_dispatch_subcommand
return
;;
esac
}
# Known subcommands & short descriptions
_claude_subcommands() {
local -a subcmds
subcmds=(
'chat:Start a new interactive chat'
'c:Continue the most recent conversation'
'r:Resume a conversation by ID'
'commit:Generate and apply a Git commit'
'review:Review a diff, PR, or file'
'edit:Edit file(s) using Claude'
'explore:Explore and summarize a codebase'
'mcp:Manage MCP servers and config'
'config:Show or edit CLI configuration'
'update:Update the Claude CLI'
'help:Show help for a subcommand'
)
_describe -t commands 'claude subcommand' subcmds
}
# Route completion based on subcommand
_claude_dispatch_subcommand() {
local -a words
words=(${words[@]}) # defensive copy
# First non-option word after 'claude'
local subcmd
for w in ${words[@]:1}; do
[[ $w == -* ]] && continue
subcmd=$w
break
done
[[ -z $subcmd ]] && { _claude_subcommands; return; }
case $subcmd in
chat)
_claude_chat
;;
c|continue)
_claude_continue
;;
r|resume)
_claude_resume
;;
commit)
_claude_commit
;;
review)
_claude_review
;;
edit)
_claude_edit
;;
explore)
_claude_explore
;;
mcp)
_claude_mcp
;;
config)
_claude_config
;;
update)
_claude_update
;;
help)
_claude_help
;;
*)
_message "No additional completions for: $subcmd"
;;
esac
}
# ---- Subcommand completion functions ----
_claude_chat() {
_arguments -C \
'(-m --model)'{-m,--model}'[Claude model]:model name:->model' \
'(-i --input)'{-i,--input}'[Attach file(s) as context]:file:_files' \
'(-p --print)'{-p,--print}'[Print full response when done]' \
'1:prompt text: ' \
'*:extra arguments: '
}
_claude_continue() {
_arguments -C \
'(-p --print)'{-p,--print}'[Print full response when done]' \
'1:optional prompt to continue with: ' \
'*:extra arguments: '
}
_claude_resume() {
_arguments -C \
'(-p --print)'{-p,--print}'[Print full response when done]' \
'1:session id: ' \
'2:prompt text: ' \
'*:extra arguments: '
}
_claude_commit() {
_arguments -C \
'--amend[Amend the previous commit]' \
'--no-verify[Skip pre-commit hooks]' \
'--all[Stage all modified files]' \
'--staged[Use only staged changes]' \
'--message=-[Override generated message]:message: ' \
'--branch=-[Describe current branch]:branch name: ' \
'*:file:_files'
}
_claude_review() {
_arguments -C \
'--staged[Review only staged changes]' \
'--patch[Review current diff/patch]' \
'--file=-[Review a specific file]:file:_files' \
'--pr=-[Review a pull request id or URL]:PR id or URL: ' \
'*:additional files or args:_files'
}
_claude_edit() {
_arguments -C \
'--in-place[Apply edits directly to files]' \
'--dry-run[Show changes without writing files]' \
'--diff[Show unified diff of edits]' \
'1:file to edit:_files' \
'*:additional files:_files'
}
_claude_explore() {
_arguments -C \
'--root=-[Root directory of project]:directory:_files -/' \
'--summary[Summarize the project structure]' \
'--map[Create or update a code map]' \
'*:paths to include:_files'
}
_claude_mcp() {
local -a mcp_sub
mcp_sub=(
'list:List configured MCP servers'
'add:Add a new MCP server'
'remove:Remove an MCP server'
'test:Test connectivity to a server'
'open:Open MCP config in editor'
)
_arguments -C \
'1:subcommand:->mcp_sub' \
'*::args:->mcp_args'
case $state in
mcp_sub)
_describe -t subcmds 'mcp subcommand' mcp_sub
;;
mcp_args)
local sub=${words[2]}
case $sub in
add)
_arguments -C \
'1:server name: ' \
'2:server URL: ' \
'*:extra options: '
;;
remove|test|open)
_arguments -C \
'1:server name: '
;;
list|*)
;;
esac
;;
esac
}
_claude_config() {
_arguments -C \
'1:action:(show edit path doctor)' \
'*:args: '
}
_claude_update() {
_arguments -C \
'--preview[Update to latest preview or beta]' \
'--force[Force re-install even if up to date]' \
'*:args: '
}
_claude_help() {
_arguments -C \
'1:command to show help for:->cmd' \
'*:args: '
[[ $state == cmd ]] && _claude_subcommands
}
# End of file

View File

@ -0,0 +1,10 @@
# Ensure compinit is available
autoload -Uz compinit
if ! typeset -f _completion_loader >/dev/null; then
compinit -u
fi
# Load our completion function
fpath=(${0:A:h} $fpath)
autoload -Uz _claude
compdef _claude claude

View File

@ -1,6 +1,7 @@
# uv plugin
This plugin automatically installs [uv](https://github.com/astral-sh/uv)'s completions for you, and keeps them up to date. It also adds convenient aliases for common usage.
This plugin automatically installs [uv](https://github.com/astral-sh/uv)'s completions for you,
and keeps them up to date. It also adds convenient aliases for common usage.
To use it, add `uv` to the plugins array in your zshrc file:
@ -10,20 +11,26 @@ plugins=(... uv)
## Aliases
| Alias | Command | Description |
|:----- |------------------------------------------------------------------------ |:-------------------------------------------------------------------- |
| uva | `uv add` | Add packages to the project |
| uvexp | `uv export --format requirements-txt --no-hashes --output-file requirements.txt --quiet` | Export the lock file to `requirements.txt` |
| uvl | `uv lock` | Lock the dependencies |
| uvlr | `uv lock --refresh` | Rebuild the lock file without upgrading dependencies |
| uvlu | `uv lock --upgrade` | Lock the dependencies to the newest compatible versions |
| uvp | `uv pip` | Manage pip packages |
| uvpy | `uv python` | Manage Python installs |
| uvpp | `uv python pin` | Pin the current project to use a specific Python version |
| uvr | `uv run` | Run commands within the project's environment |
| uvrm | `uv remove` | Remove packages from the project |
| uvs | `uv sync` | Sync the environment with the lock file |
| uvsr | `uv sync --refresh` | "Force" sync the environment with the lock file (ignore cache) |
| uvsu | `uv sync --upgrade` | Sync the environment, allowing upgrades and ignoring the lock file |
| uvup | `uv self update` | Update the UV tool to the latest version |
| uvv | `uv venv` | Manage virtual environments |
| Alias | Command | Description |
| :---- | ---------------------------------------------------------------------------------------- | :-------------------------------------------------------------------- |
| uva | `uv add` | Add packages to the project |
| uvexp | `uv export --format requirements-txt --no-hashes --output-file requirements.txt --quiet` | Export the lock file to `requirements.txt` |
| uvi | `uv init` | Initialize a new project in current workspace and environment. |
| uvinw | `uv init --no-workspace` | Initialize a new project in a new workspace and environment |
| uvl | `uv lock` | Lock the dependencies |
| uvlr | `uv lock --refresh` | Rebuild the lock file without upgrading dependencies |
| uvlu | `uv lock --upgrade` | Lock the dependencies to the newest compatible versions |
| uvp | `uv pip` | Manage pip packages |
| uvpi | `uv python install` | Install a specific version of python |
| uvpl | `uv python list` | Lists all python version installed |
| uvpp | `uv python pin` | Pin the current project to use a specific Python version |
| uvpu | `uv python uninstall` | Remove a specific version of python |
| uvpy | `uv python` | Manage Python installs |
| uvr | `uv run` | Run commands within the project's environment |
| uvrm | `uv remove` | Remove packages from the project |
| uvs | `uv sync` | Sync the environment with the lock file |
| uvsr | `uv sync --refresh` | "Force" sync the environment with the lock file (ignore cache) |
| uvsu | `uv sync --upgrade` | Sync the environment, allowing upgrades and ignoring the lock file |
| uvtr | `uv tree` | Displays the full dependency tree for the current project environment |
| uvup | `uv self update` | Update the UV tool to the latest version |
| uvv | `uv venv` | Manage virtual environments |

View File

@ -7,10 +7,15 @@ alias uv="noglob uv"
alias uva='uv add'
alias uvexp='uv export --format requirements-txt --no-hashes --output-file requirements.txt --quiet'
alias uvi='uv init'
alias uvinw='uv init --no-workspace'
alias uvl='uv lock'
alias uvlr='uv lock --refresh'
alias uvlu='uv lock --upgrade'
alias uvp='uv pip'
alias uvpi='uv python install'
alias uvpl='uv python list'
alias uvpu='uv python uninstall'
alias uvpy='uv python'
alias uvpp='uv python pin'
alias uvr='uv run'
@ -18,6 +23,7 @@ alias uvrm='uv remove'
alias uvs='uv sync'
alias uvsr='uv sync --refresh'
alias uvsu='uv sync --upgrade'
alias uvtr='uv tree'
alias uvup='uv self update'
alias uvv='uv venv'