Initial commit
This commit is contained in:
52
skills/working-with-jj/scripts/jj-flag-update
Executable file
52
skills/working-with-jj/scripts/jj-flag-update
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
# Update status flag in revision description
|
||||
# Usage: jj-flag-update <REV> <TO_FLAG>
|
||||
# TO_FLAG is: todo, wip, untested, broken, review, or "done" (removes flag)
|
||||
# Example: jj-flag-update @ wip
|
||||
# Example: jj-flag-update mxyz done
|
||||
#
|
||||
# Automatically detects the current flag and replaces it.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -ne 2 ]]; then
|
||||
echo "Usage: jj-flag-update <REV> <TO_FLAG>" >&2
|
||||
echo "Flags: todo, wip, untested, broken, review, done (done removes flag)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rev="$1"
|
||||
to_flag="$2"
|
||||
|
||||
# Get current description
|
||||
desc=$(jj log -r "$rev" -n1 --no-graph -T description)
|
||||
|
||||
# Detect current flag
|
||||
current_flag=""
|
||||
for flag in todo wip untested broken review; do
|
||||
if [[ "$desc" =~ ^\[${flag}\] ]]; then
|
||||
current_flag="$flag"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ -z "$current_flag" ]]; then
|
||||
if [[ "$to_flag" == "done" ]]; then
|
||||
# No flag to remove, nothing to do
|
||||
exit 0
|
||||
else
|
||||
# No current flag - prepend the new one
|
||||
echo "[${to_flag}] ${desc}" | jj desc -r "$rev" --stdin
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build sed pattern
|
||||
if [[ "$to_flag" == "done" ]]; then
|
||||
# Remove the flag (and trailing space)
|
||||
sed_pattern="s/\[${current_flag}\] //"
|
||||
else
|
||||
sed_pattern="s/\[${current_flag}\]/[${to_flag}]/"
|
||||
fi
|
||||
|
||||
echo "$desc" | sed "$sed_pattern" | jj desc -r "$rev" --stdin
|
||||
Reference in New Issue
Block a user