diff --git a/conf/bash/scripts/git-commit-chunk-text.sh b/conf/bash/scripts/git-commit-chunk-text.sh index cb63a1eb..a32810d3 100755 --- a/conf/bash/scripts/git-commit-chunk-text.sh +++ b/conf/bash/scripts/git-commit-chunk-text.sh @@ -68,7 +68,6 @@ commit_with_text() { done # Execute the git commit command - echo "Executing: ${git_cmd[*]}" "${git_cmd[@]}" } diff --git a/conf/bash/scripts/jj-ai-commit.sh b/conf/bash/scripts/jj-ai-commit.sh new file mode 100755 index 00000000..d82e83ae --- /dev/null +++ b/conf/bash/scripts/jj-ai-commit.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash + +# This script will run the jj describe command with input text for a given revision +# Input text is long text with empty lines. +# First line is commit message, rest is description. +# to make long description with line break, we need to use multiple `-m` +# Eg: jj describe -r -m "title" -m "description line 1" -m "description line 2" ......... + +set -euo pipefail + +# Function to show usage +show_usage() { + echo "Usage: $0 [OPTIONS]" + echo "Updates commit message for the given revision using multi-line text input" + echo "" + echo "Arguments:" + echo " Revision to update (required)" + echo "" + echo "Options:" + echo " -h, --help Show this help message" + echo " -f, --file Read commit message from file" + echo "" + echo "Examples:" + echo " echo 'Title\n\nDescription line 1\nDescription line 2' | $0 @" + echo " $0 @ -f commit_message.txt" + echo " $0 @ < commit_message.txt" + echo " aichat 'generate commit message' | $0 @" +} + +# Function to process commit text and execute jj describe +describe_with_text() { + local rev="$1" + local input_text="$2" + + # Split input into lines and process + local lines=() + + # Use readarray to split input into lines + readarray -t lines <<< "$input_text" + local line_count=${#lines[@]} + + # Check if we have at least one line + if [[ $line_count -eq 0 ]]; then + echo "Error: No commit message provided" >&2 + exit 1 + fi + + # First line is the commit title + local commit_title="${lines[0]}" + + # Check if title is empty + if [[ -z "$commit_title" ]]; then + echo "Error: Commit title cannot be empty" >&2 + exit 1 + fi + + # Build jj describe command + local jj_cmd=("jj" "describe" "--no-edit" "-r" "$rev" "-m" "$commit_title") + + # Add description lines (skip first line and any immediately following empty lines) + local in_description=false + for ((i=1; i&2 + show_usage + exit 1 + fi + + # First argument is the revision + rev="$1" + shift + + # Parse remaining command line arguments + while [[ $# -gt 0 ]]; do + case $1 in + -h|--help) + show_usage + exit 0 + ;; + -f|--file) + if [[ -z "${2:-}" ]]; then + echo "Error: -f/--file requires a filename" >&2 + exit 1 + fi + read_from_file="$2" + shift 2 + ;; + *) + echo "Error: Unknown option $1" >&2 + show_usage + exit 1 + ;; + esac + done + + # Read input based on source + if [[ -n "$read_from_file" ]]; then + # Read from file + if [[ ! -f "$read_from_file" ]]; then + echo "Error: File '$read_from_file' not found" >&2 + exit 1 + fi + input_text=$(cat "$read_from_file") + elif [[ ! -t 0 ]]; then + # Read from stdin (pipe or redirect) + input_text=$(cat) + else + # No input source provided + echo "Error: No input provided. Use -f to read from file or pipe/redirect input" >&2 + show_usage + exit 1 + fi + + # Check if input is empty + if [[ -z "$input_text" ]]; then + echo "Error: No input provided" >&2 + exit 1 + fi + + # Process and describe + describe_with_text "$rev" "$input_text" +} + +# Run main function with all arguments +main "$@" diff --git a/conf/bash/scripts/jj-commit-context.sh b/conf/bash/scripts/jj-commit-context.sh new file mode 100755 index 00000000..5037af2e --- /dev/null +++ b/conf/bash/scripts/jj-commit-context.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash + +# get context for llm jj commit message generation +# script should redirect output to stdout, so it can be used in a pipeline + +## The context should include: + +# 1. Changes in the specified revision +# 2. Last 10 commit messages + +## It should output in well formatted text + +## Steps + +### 1. check if repo is a jj repository, exit 1 if not +### 2. Get the revision argument (default to @) +### 3. Get changes for the specified revision +### 4. Get last 10 commit messages +### 5. Format the output in well formatted text +### 6. Redirect the output to stdout +### 7. Exit 0 + +set -euo pipefail + +# Function to check if we're in a jj repository +check_jj_repo() { + if ! jj status >/dev/null 2>&1; then + echo "Error: Not in a jj repository" >&2 + exit 1 + fi +} + +# Function to get the revision argument +get_revision() { + local rev="${1:-@}" + echo "$rev" +} + +# Function to get changes for the specified revision +get_revision_changes() { + local rev="$1" + echo "=== STAGED CHANGES ===" + echo + # Show the actual diff + echo "Changes:" + jj diff -r "$rev" --stat --color=never --no-pager + echo + jj diff -r "$rev" --color=never --no-pager + echo +} + +# Function to get last 10 commit messages using template +get_recent_commits() { + local rev="$1" + echo "=== RECENT COMMIT HISTORY ===" + echo + echo "Last 10 commits:" + # Use template to format output similar to git log --oneline + jj log -n 10 -r "..$rev" --no-pager --no-graph --color=never \ + -T 'change_id.short() ++ " " ++ description.first_line() ++ "\n"' + echo +} + +# Function to show usage +usage() { + echo "Usage: $0 [revision]" + echo " revision: The revision to analyze (default: @)" + echo " Examples:" + echo " $0 # Analyze working copy (@)" + echo " $0 @- # Analyze parent of working copy" + echo " $0 abc123 # Analyze specific revision" + exit 1 +} + +# Main function +main() { + # Check for help flag + if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then + usage + fi + + check_jj_repo + + local rev + rev=$(get_revision "${1:-}") + + echo "Git Commit Context" + echo "==================" + echo + + get_revision_changes "$rev" + get_recent_commits "$rev" + + echo "=== END OF CONTEXT ===" +} + +# Run main function +main "$@" + +exit 0 diff --git a/conf/bash/scripts/jj-split-on-bookmark.sh b/conf/bash/scripts/jj-split-on-bookmark.sh new file mode 100755 index 00000000..3c013d69 --- /dev/null +++ b/conf/bash/scripts/jj-split-on-bookmark.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash + +# man jj-split +# 1. jj split -r @ -i -d -m "WIP: empty message" +# 2. jj mv-next + +# This script does: +# 1. Accept required argument -b for bookmark +# 2. Accept optional argument -ai for using ai to generate commit. + +set -euo pipefail + +BASH_SCRIPT_DIR="$HOME/.local/bash/scripts" +AI_COMMIT_CONTEXT_SCRIPT="$BASH_SCRIPT_DIR/jj-commit-context.sh" +JJ_AI_COMMIT_SCRIPT="$BASH_SCRIPT_DIR/jj-ai-commit.sh" + +# Function to show usage +show_usage() { + echo "Usage: