Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions adapters/ai/droid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Droid AI adapter

# Check if Droid is available
ai_can_start() {
command -v droid >/dev/null 2>&1
}

# Start Droid in a directory
# Usage: ai_start path [args...]
ai_start() {
local path="$1"
shift

if ! ai_can_start; then
log_error "Droid not found. Install from https://github.com/factory-droid/droid"
return 1
fi

if [ ! -d "$path" ]; then
log_error "Directory not found: $path"
return 1
fi

(cd "$path" && droid "$@")
}
81 changes: 81 additions & 0 deletions completions/gtr.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env zsh
# Zsh completion for gtr

# Load the completion function
_gtr() {
local -a commands
commands=(
'new:Create a new worktree'
'go:Navigate to worktree'
'rm:Remove worktree(s)'
'editor:Open worktree in editor'
'ai:Start AI coding tool'
'ls:List all worktrees'
'list:List all worktrees'
'clean:Remove stale worktrees'
'doctor:Health check'
'adapter:List available adapters'
'config:Manage configuration'
'version:Show version'
'help:Show help'
)

local -a branches all_options
# Get branch names
branches=(${(f)"$(git branch --format='%(refname:short)' 2>/dev/null)"})
# Add special ID '1' for main repo
all_options=("1" "${branches[@]}")

if (( CURRENT == 2 )); then
_describe 'commands' commands
elif (( CURRENT == 3 )); then
case "$words[2]" in
go|editor|ai|rm)
_describe 'branch names' all_options
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

Verify _describe is the correct Zsh completion function for branches without descriptions.

The code uses _describe 'branch names' all_options to suggest branches, but _describe is typically used when the array has "value:description" entries (like the commands array at lines 7-21). Since branch names lack descriptions, _values may be more appropriate or even direct completion via array expansion. Verify this is correct against the Zsh completion API.

If correction is needed, replace line 34 with:

-        _describe 'branch names' all_options
+        _values 'branch names' "${all_options[@]}"

🌐 Web query:

Zsh _describe function usage - should it be used with plain arrays or value:description format?

💡 Result:

Use the value:description form. _describe expects the first array to contain entries like "completion:description" (or a first array of value:description and a second parallel array of the actual values). Plain arrays without colon are allowed but won’t supply per-item descriptions. [1][2]

Sources:
[1] zshcompsys manual (man page) — description of _describe and the "completion:description" array format.
[2] Arch/Ubuntu zshcompsys man pages — same explanation and examples.


Based on the search results, examples in Zsh completion documentation show _values used with plain arrays as _values 'profiles' $(_netctl_profiles), confirming this is the idiomatic approach for plain arrays without descriptions. The original review's concern is valid—while _describe allows plain arrays, it won't supply per-item descriptions and is semantically designed for "value:description" entries.

Use _values instead of _describe for branch name completion at line 34.

This is a code quality improvement. Replace with:

-        _describe 'branch names' all_options
+        _values 'branch names' "${all_options[@]}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_describe 'branch names' all_options
_values 'branch names' "${all_options[@]}"
🤖 Prompt for AI Agents
In completions/gtr.zsh around line 34, the completion currently uses `_describe
'branch names' all_options` which is intended for value:description pairs and
won't provide simple list-style completions; replace this with `_values 'branch
names' all_options` (or the appropriate function call that returns a plain
array) so branch names are completed idiomatically without expecting per-item
descriptions.

;;
new)
_arguments \
'--from[Base ref]:ref:' \
'--track[Track mode]:mode:(auto remote local none)' \
'--no-copy[Skip file copying]' \
'--no-fetch[Skip git fetch]' \
'--force[Allow same branch in multiple worktrees]' \
'--name[Custom folder name suffix]:name:' \
'--yes[Non-interactive mode]'
;;
config)
_values 'config action' get set unset
;;
esac
elif (( CURRENT >= 4 )); then
case "$words[2]" in
rm)
_arguments \
'--delete-branch[Delete branch]' \
'--force[Force removal even if dirty]' \
'--yes[Non-interactive mode]'
;;
config)
case "$words[3]" in
get|set|unset)
_values 'config key' \
'gtr.worktrees.dir' \
'gtr.worktrees.prefix' \
'gtr.defaultBranch' \
'gtr.editor.default' \
'gtr.ai.default' \
'gtr.copy.include' \
'gtr.copy.exclude' \
'gtr.hook.postCreate' \
'gtr.hook.postRemove'
;;
esac
;;
esac
fi
}

_gtr "$@"

# Register completion
compdef _gtr gtr