Skip to content

Commit fed15db

Browse files
committed
Refactor file handling and improve shell script robustness
- Replace `sed` with bash parameter expansion for file parsing - Simplify conditionals and diff checks - Use more robust shell practices - Add explicit quoting and numeric comparisons
1 parent 9f2ed49 commit fed15db

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

apply-md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ FILES_FILE="$TEMP_DIR/files.txt"
3939
cleanup() {
4040
rm -rf "$TEMP_DIR"
4141
}
42+
43+
# Register cleanup on exit
4244
trap cleanup EXIT
4345

4446
# Extract code blocks and their file names
@@ -110,8 +112,7 @@ apply_block() {
110112
fi
111113

112114
# Check for changes
113-
diff -q "$file" "$content_file" > /dev/null
114-
if [ $? -eq 0 ]; then
115+
if diff -q "$file" "$content_file" > /dev/null; then
115116
if [ "$VERBOSE" = true ]; then
116117
echo "No changes needed for: $file"
117118
fi

git-context

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ if [ -n "$status_output" ]; then
6969
# Extract the status code (first two characters)
7070
status_code="${line:0:2}"
7171
# Extract the filename (everything after the status code and whitespace)
72-
file=$(echo "$line" | sed 's/^.. *//')
72+
file=${line#??}
73+
file=${file#"${file%%[! ]*}"} # Remove leading whitespace
7374
status_desc=""
7475

7576
# Determine the status description
@@ -89,10 +90,10 @@ if [ -n "$status_output" ]; then
8990
fi
9091

9192
# Show recent commits
92-
if [ $RECENT_COMMITS -gt 0 ]; then
93+
if [ "$RECENT_COMMITS" -gt 0 ]; then
9394
echo "## Recent Commits (for reference)"
9495
echo ""
95-
git log -n $RECENT_COMMITS --pretty=format:"- %h: %s (%an, %ar)" | while read -r line; do
96+
git log -n "$RECENT_COMMITS" --pretty=format:"- %h: %s (%an, %ar)" | while read -r line; do
9697
echo "$line"
9798
done
9899
echo ""

0 commit comments

Comments
 (0)