This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
git-chord is a zsh plugin that provides vim-style composable git commands. Users chain single-character git operations into "chords" that execute sequentially, similar to vim keybindings.
Example: g acp "Fix bug" executes: git add . → git commit -m "Fix bug" → git push
All functionality lives in one zsh file. The architecture consists of:
-
Three Command Registries (associative arrays at top of file):
GIT_CHORD_CMDS: Single-char commands (a, c, p, x, etc.)GIT_CHORD_MULTI: Multi-char commands (pf, pu, ra, rc, etc.)GIT_CHORD_MACROS: Macro commands that capture current branch (R, M, W)
-
Parser Pipeline (_git_chord_parse:94-186):
- Parses chord string character-by-character
- Handles three types of argument binding:
- Inline quoted:
x"branch"binds "branch" explicitly to x - Positional:
xacp branch "msg"binds left-to-right to commands that need args - Defaults: Some commands have defaults (x defaults to "main")
- Inline quoted:
- Macros expand to multiple commands with {branch} substitution
- Commands execute sequentially; failures stop the chain
-
Executor (_git_chord_exec:188-229):
- Takes parsed command + argument
- Looks up template from registry
- Handles optional args with
::defaultsyntax in templates - Substitutes {} with argument value
- Uses
evalto execute the final git command
Single-char (GIT_CHORD_CMDS):
[char]="needs_arg:template::default"
needs_arg: 0=none, 1=required, 2=optionaltemplate: Command with {} for substitution::default: Optional default value for arg
Multi-char (GIT_CHORD_MULTI):
[chars]="full git command"
Macros (GIT_CHORD_MACROS):
[char]="cmd1:cmd2:cmd3 arg:cmd4 {branch}"
- Colon-separated command sequence
{branch}gets replaced with branch at chord start
No automated test suite exists. Manual testing workflow:
- Source the file:
source git-chord.zsh - Test in a git repo:
g <chord> - Use
ghelpto verify help output - Test common chords:
g acp,g xF,g R, etc. - Test argument binding: both inline quoted and positional
When adding/modifying commands:
- Add to correct registry at top of file (lines 14-76)
- Follow the format exactly - parser depends on it
- Test argument binding - inline quoted vs positional
- Verify macro expansion if adding macros
- Update ghelp() function (lines 283-340) if adding user-facing commands
- Consider adding convenience alias (lines 251-277) for muscle memory
Critical: The parser uses character indices and string slicing. Changes to parsing logic require careful testing of:
- Quote handling in _git_chord_parse:150-158
- Multi-char command detection (must check before single-char)
- Macro expansion with {branch} substitution
Users install via:
git clone <repo> ~/.git-chord
source ~/.git-chord/git-chord.zsh # add to .zshrcThe install.sh script automates this but is optional.
- All functionality in one file - users can copy/paste it anywhere
- No external dependencies - pure zsh, no ruby/python/node
- Fail fast - if any command in chain fails, stop execution
- Branch capture - macros capture branch at chord START, not during expansion
- Positional args consumed left-to-right - commands that need args grab from positional array in order