Commit 7ff9f2ee0aac54eef2720853a2d2f116bbfb687e Parent: ee2659019562bf1fddc95115797b1560fe1e9fb6 Author: Matt Colligan <matt@edra.ai> Date: 2026-04-29 12:39:27 +0100 Committer: Matt Colligan <matt@edra.ai> Committed: 2026-04-29 12:39:27 +0100 alias
claude-context/plugin.zsh Added
@@ -0,0 +1,54 @@ +cw() { + local suffix="" + [[ -n "$CLAUDE_CONTEXT_ID" ]] && suffix=".$CLAUDE_CONTEXT_ID" + local wt_file="$HOME/.local/share/claude/worktree${suffix}" + [[ -f "$wt_file" ]] || return 1 + local wt + wt=$(<"$wt_file") + [[ -d "$wt" ]] || return 1 + cd "$wt" +} + +_zsh_autosuggest_strategy_claude() { + emulate -L zsh + setopt EXTENDED_GLOB + + typeset -g suggestion + local suffix="" + [[ -n "$CLAUDE_CONTEXT_ID" ]] && suffix=".$CLAUDE_CONTEXT_ID" + local context_file="$HOME/.local/share/claude/context-files${suffix}" + [[ -f "$context_file" ]] || return + + local buffer="$1" + local cmd partial + + [[ "$buffer" =~ '^(v|vi|vim|nvim)( +(.*))?$' ]] || return + cmd="${match[1]}" + partial="${match[3]}" + + local -a files + files=("${(@f)$(< "$context_file")}") + (( ${#files} )) || return + + local f rel + + if [[ -n "$partial" ]]; then + for f in "${(@Oa)files}"; do + [[ -f "$f" ]] || continue + rel="${f#$PWD/}" + [[ "$rel" == ${partial}* ]] && { suggestion="$cmd $rel"; return } + done + for f in "${(@Oa)files}"; do + [[ -f "$f" ]] || continue + rel="${f#$PWD/}" + [[ "$rel" == *${partial}* ]] && { suggestion="$cmd $rel"; return } + done + else + for f in "${(@Oa)files}"; do + [[ -f "$f" ]] || continue + rel="${f#$PWD/}" + suggestion="$cmd $rel" + return + done + fi +}
claude-context/hook.sh Added
@@ -0,0 +1,55 @@ +#!/bin/bash +input=$(cat) +tool_name=$(echo "$input" | jq -r '.tool_name // empty') + +suffix="" +[ -n "$CLAUDE_CONTEXT_ID" ] && suffix=".$CLAUDE_CONTEXT_ID" +base="$HOME/.local/share/claude" +mkdir -p "$base" +wt_file="${base}/worktree${suffix}" + +if [ "$tool_name" = "ExitWorktree" ]; then + rm -f "$wt_file" + exit 0 +fi + +if [ "$tool_name" = "EnterWorktree" ]; then + cwd=$(echo "$input" | jq -r '.cwd // empty') + [ -n "$cwd" ] && [ -d "$cwd" ] && echo "$cwd" > "$wt_file" + exit 0 +fi + +check_worktree() { + local dir="$1" + [ -z "$dir" ] && return + local toplevel + toplevel=$(git -C "$dir" rev-parse --show-toplevel 2>/dev/null) + if [ -n "$toplevel" ] && [ -f "$toplevel/.git" ]; then + echo "$toplevel" > "$wt_file" + fi +} + +if [ "$tool_name" = "Bash" ]; then + cwd=$(echo "$input" | jq -r '.cwd // empty') + check_worktree "$cwd" + exit 0 +fi + +file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty') +[ -z "$file_path" ] && exit 0 +[ -f "$file_path" ] || exit 0 + +context_file="${base}/context-files${suffix}" +tmp="${context_file}.$$" +if [ -f "$context_file" ]; then + grep -v -F -x "$file_path" "$context_file" > "$tmp" 2>/dev/null || : > "$tmp" +else + : > "$tmp" +fi +echo "$file_path" >> "$tmp" +tail -50 "$tmp" > "$context_file" +rm -f "$tmp" + +check_worktree "$(dirname "$file_path")" + +exit 0
aliases Modified
@@ -78,6 +78,7 @@ alias gs='git status' alias ad='git add' alias adp='git add --patch' +alias adn='git add -A -N' alias co='git commit' alias cm='git commit -m' alias ca='git commit --amend'