Update hooks to use read -r and printf

This portably avoids any interpretation of backslash escapes by the
shell.
This commit is contained in:
Dustin J. Mitchell 2025-07-02 15:13:28 -04:00
parent 97058dad79
commit 68cf122cea
No known key found for this signature in database
24 changed files with 50 additions and 49 deletions

View file

@ -10,7 +10,7 @@ read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo "$new_task" printf "%s\n" "$new_task"
echo 'on-add' echo 'on-add'
# Status: # Status:

View file

@ -2,11 +2,11 @@
read -r new_task read -r new_task
if (echo "$new_task" | grep -qE '[tT]eh'); if (printf "%s" "$new_task" | grep -qE '[tT]eh');
then then
new_task=$(echo "$new_task" | sed -r 's/([tT])eh/\1he/g') new_task=$(printf "%s" "$new_task" | sed -r 's/([tT])eh/\1he/g')
echo "Auto-corrected 'teh' --> 'the'" echo "Auto-corrected 'teh' --> 'the'"
fi fi
echo "$new_task" printf "%s" "$new_task"
exit 0 exit 0

View file

@ -12,8 +12,8 @@ read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo "$modified_task" printf "%s" "$modified_task"
echo 'on-modify' printf "%s" 'on-modify'
# Status: # Status:
# - 0: JSON accepted, non-JSON is feedback. # - 0: JSON accepted, non-JSON is feedback.

View file

@ -5,12 +5,12 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo $new_task printf "%s\n" "$new_task"
echo 'FEEDBACK' echo 'FEEDBACK'
# Status: # Status:

View file

@ -5,7 +5,7 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -5,12 +5,12 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo $new_task printf "%s\n" "$new_task"
echo '{"description":"extra","status":"pending"}' echo '{"description":"extra","status":"pending"}'
echo 'FEEDBACK' echo 'FEEDBACK'

View file

@ -5,7 +5,7 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -5,7 +5,7 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -5,7 +5,7 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -2,17 +2,17 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
if (echo $new_task | grep -qE '[tT]eh'); if (printf "%s\n" "$new_task" | grep -qE '[tT]eh');
then then
new_task=$(echo $new_task | sed -r 's/([tT])eh/\1he/g') new_task=$(printf "%s\n" "$new_task" | sed -r 's/([tT])eh/\1he/g')
fi fi
# Output: # Output:
# - JSON, modified # - JSON, modified
# - Optional feedback/error. # - Optional feedback/error.
echo $new_task printf "%s\n" "$new_task"
echo 'FEEDBACK' echo 'FEEDBACK'
# Status: # Status:

View file

@ -5,12 +5,12 @@
# Input: # Input:
# - Line of JSON for proposed new task. # - Line of JSON for proposed new task.
read new_task read -r new_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo $new_task printf "%s\n" "$new_task"
echo 'FEEDBACK' echo 'FEEDBACK'
# Status: # Status:

View file

@ -2,9 +2,9 @@
echo "on-add executed" echo "on-add executed"
while read TASK; do while read -r TASK; do
echo "New task $TASK" echo "New task $TASK"
echo $TASK printf "%s\n" "$TASK"
done done
exit 0 exit 0

View file

@ -5,7 +5,7 @@
# Input: # Input:
# - Read-only line of JSON for each task added/modified # - Read-only line of JSON for each task added/modified
while read modified_task while read -r modified_task
do do
echo 'CHANGED TASK' echo 'CHANGED TASK'
done done

View file

@ -5,7 +5,7 @@
# Input: # Input:
# - Read-only line of JSON for each task added/modified # - Read-only line of JSON for each task added/modified
while read modified_task while read -r modified_task
do do
echo 'CHANGED TASK' echo 'CHANGED TASK'
done done

View file

@ -2,7 +2,7 @@
echo "on-exit executed" echo "on-exit executed"
while read TASK; do while read -r TASK; do
echo "New/modified task $TASK" echo "New/modified task $TASK"
done done

View file

@ -6,13 +6,13 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo $modified_task printf "%s\n" "$modified_task"
echo 'FEEDBACK' echo 'FEEDBACK'
# Status: # Status:

View file

@ -6,8 +6,8 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -6,13 +6,13 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo $modified_task printf "%s\n" "$modified_task"
echo '{"description":"extra","status":"pending"}' echo '{"description":"extra","status":"pending"}'
echo 'FEEDBACK' echo 'FEEDBACK'

View file

@ -6,8 +6,8 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -6,8 +6,8 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -6,8 +6,8 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.

View file

@ -6,13 +6,13 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo $modified_task printf "%s\n" "$modified_task"
echo 'FEEDBACK' echo 'FEEDBACK'
# Status: # Status:

View file

@ -6,13 +6,13 @@
# Input: # Input:
# - line of JSON for the original task # - line of JSON for the original task
# - line of JSON for the modified task, the diff being the modification # - line of JSON for the modified task, the diff being the modification
read original_task read -r original_task
read modified_task read -r modified_task
# Output: # Output:
# - JSON, modified or unmodified. # - JSON, modified or unmodified.
# - Optional feedback/error. # - Optional feedback/error.
echo $original_task printf "%s\n" "$original_task"
# Status: # Status:
# - 0: JSON accepted, non-JSON is feedback. # - 0: JSON accepted, non-JSON is feedback.

View file

@ -2,9 +2,10 @@
echo "on-modify executed" echo "on-modify executed"
while read TASK MODTASK; do read -r TASK
echo "Existing task $TASK modified to $MODTASK" read -r MODTASK
echo $MODTASK
done echo "Existing task $TASK modified to $MODTASK"
printf "%s\n" "$MODTASK"
exit 0 exit 0