Skip to content

Commit d04ce9e

Browse files
committed
Fix script path resolution and improve usability for context scripts
1 parent 547cbbb commit d04ce9e

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

apply-md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ while [[ "$#" -gt 0 ]]; do
1515
--create-missing) CREATE_MISSING=true; shift ;;
1616
--verbose) VERBOSE=true; shift ;;
1717
--help|-h)
18-
echo "Usage: ./apply-md [options]"
18+
echo "Usage: apply-md [options]"
1919
echo ""
2020
echo "Options:"
2121
echo " --dry-run Preview changes without applying them"

autocommit

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
#!/bin/bash
2-
git commit -am "$(./git-context | llm -m openrouter/anthropic/claude-3.5-haiku)" -e
2+
3+
# Get script directory (works even when called from other directories)
4+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
5+
6+
# Use the full path to git-context
7+
git commit -am "$("$SCRIPT_DIR/git-context" | llm -m openrouter/anthropic/claude-3.5-haiku)" -e

context

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# context - Simplified Code Context Generator
44
# Generates contextual information from a codebase to send to an LLM
55

6+
# Get script directory (works even when called from other directories)
7+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
8+
69
# Default values
710
INCLUDE=()
811
EXCLUDE=()
@@ -21,7 +24,7 @@ while [[ "$#" -gt 0 ]]; do
2124
--show-sizes) SHOW_FILE_SIZES=true; shift ;;
2225
--no-ls-files) SHOW_LS_FILES=false; shift ;;
2326
--help|-h)
24-
echo "Usage: ./context [options] [include-pattern1 include-pattern2 ...]"
27+
echo "Usage: context [options] [include-pattern1 include-pattern2 ...]"
2528
echo ""
2629
echo "Options:"
2730
echo " --include=<pattern> File pattern to include (e.g., \"src/*.js\")"
@@ -41,8 +44,8 @@ while [[ "$#" -gt 0 ]]; do
4144
echo " \"!test/*\" - Exclude all files in test directory"
4245
echo ""
4346
echo "Examples:"
44-
echo " ./context --include=\"src/*.js\" --exclude=\"*.test.js\""
45-
echo " ./context \"src/*.js\" \"*.md\" --max-size=1MB"
47+
echo " context --include=\"src/*.js\" --exclude=\"*.test.js\""
48+
echo " context \"src/*.js\" \"*.md\" --max-size=1MB"
4649
exit 0
4750
;;
4851
--*) echo "Unknown parameter: $1"; exit 1 ;;

git-context

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
#!/bin/bash
22

3-
# simplified-git-context - Minimalist Git Context Generator for Commit Messages
3+
# git-context - Minimalist Git Context Generator for Commit Messages
44
# Generates essential git-related context to help LLMs create meaningful commit messages
55

6+
# Get script directory (works even when called from other directories)
7+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
8+
69
# Default values
710
RECENT_COMMITS=3
8-
PROMPT_FILE="prompts/commit_prompt.txt"
11+
PROMPT_FILE="$SCRIPT_DIR/prompts/commit_prompt.txt"
912
INCLUDE_PROMPT=true
1013

1114
# Parse arguments
1215
while [[ "$#" -gt 0 ]]; do
1316
case $1 in
1417
--recent-commits=*) RECENT_COMMITS="${1#*=}"; shift ;;
15-
--prompt=*) PROMPT_FILE="${1#*=}"; shift ;;
18+
--prompt=*)
19+
# If the path is relative and doesn't start with /, treat it as relative to script dir
20+
if [[ "${1#*=}" != /* ]]; then
21+
PROMPT_FILE="$SCRIPT_DIR/${1#*=}"
22+
else
23+
PROMPT_FILE="${1#*=}"
24+
fi
25+
shift
26+
;;
1627
--no-prompt) INCLUDE_PROMPT=false; shift ;;
1728
--help|-h)
18-
echo "Usage: ./git-context [options]"
29+
echo "Usage: git-context [options]"
1930
echo ""
2031
echo "Options:"
2132
echo " --recent-commits=<num> Show most recent N commits for context (default: 3)"
2233
echo " --prompt=<file> Use custom commit message prompt from file (default: prompts/commit_prompt.txt)"
34+
echo " (Relative paths will be resolved from the script's directory)"
2335
echo " --no-prompt Don't include commit message prompt"
2436
echo " --help, -h Show this help message"
2537
exit 0

0 commit comments

Comments
 (0)