Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions conf/bash/scripts/ai-commit-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# Wrapper script for ai-commit that properly handles pipeline failures
# This ensures that if any step in the pipeline fails, the entire process stops

set -euo pipefail

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Define the pipeline components
CONTEXT_SCRIPT="${SCRIPT_DIR}/git-commit-context.sh"
CHUNK_SCRIPT="${SCRIPT_DIR}/git-commit-chunk-text.sh"

# First, run the context script and capture its output
# If it fails, the script will exit here due to set -e
context_output=$("$CONTEXT_SCRIPT")

# If we get here, the context script succeeded, so continue with the pipeline
echo "$context_output" | aichat --role git-commit -S | "$CHUNK_SCRIPT"
113 changes: 70 additions & 43 deletions conf/fish/funcs/_fzf-jj-bookmarks.fish
Original file line number Diff line number Diff line change
@@ -1,54 +1,81 @@
function _fzf-jj-bookmarks --description "Search for jujutsu bookmarks or git branches"
# Get the current token as initial query
function _fzf-jj-bookmarks-git --description "fzf for git branches"
set -l query ""
if status is-interactive
set query (commandline --current-token)
end

# Try git first
if git rev-parse --git-dir &>/dev/null
set -f lines (git branch --sort=-committerdate --color=always | sed 's/^[* ] //' | fzf --cycle --tmux 98% --ansi --layout=reverse \
--scheme=path \
--query="$query" \
--preview='git log --color=always --oneline -10 {}' \
--preview-label='Recent Commits' \
--bind='ctrl-y:execute-silent(echo {} | pbcopy)' \
--header='Enter: select branch, Ctrl-Y: copy branch name' \
--border=rounded)

if test $status -eq 0
set -l branch (echo $lines | string trim)
if status is-interactive
commandline --current-token --replace $branch
commandline --function repaint
else
echo $branch
end
if not git rev-parse --git-dir &>/dev/null
return 1
end
set -f lines (git branch --sort=-committerdate --color=always | sed 's/^[* ] //' | fzf --cycle --tmux 98% --ansi --layout=reverse \
--scheme=path \
--query="$query" \
--preview='git log --color=always --oneline -10 {}' \
--preview-label='Recent Commits' \
--bind='ctrl-y:execute-silent(echo {} | pbcopy)' \
--header='Enter: select branch, Ctrl-Y: copy branch name' \
--border=rounded)
set -l fzf_status $status
if test $fzf_status -eq 0
set -l branch (echo $lines | string trim)
if status is-interactive
commandline --current-token --replace $branch
commandline --function repaint
else
echo $branch
end
# Fallback to jj if not in a git repo
else if jj root --quiet &>/dev/null
set -f lines (jj bookmark list --sort committer-date- --quiet --no-pager --color always | grep -v '^[[:space:]]' | grep -v '\(deleted\)' | fzf --cycle --tmux 98% --ansi --layout=reverse \
--scheme=path \
--query="$query" \
--preview='jj log --color=always -r "stack($(echo {} | cut -d: -f2 | awk "{print \\$1}" | string trim))" --no-graph' \
--preview-label='Commit Details' \
--bind='ctrl-y:execute-silent(echo {} | cut -d: -f2 | awk "{print \\$1}" | string trim | pbcopy)' \
--header='Enter: select bookmark, Ctrl-Y: copy revset' \
--border=rounded)
end
return $fzf_status
end

if test $status -eq 0
set -l bookmark (echo $lines | cut -d: -f1 | string trim)
if status is-interactive
commandline --current-token --replace $bookmark
commandline --function repaint
else
echo $bookmark
end
end
else
echo "Not in a jj or git repository" >&2
function _fzf-jj-bookmarks-jj --description "fzf for jj bookmarks"
set -l query ""
if status is-interactive
set query (commandline --current-token)
end
if not jj root --ignore-working-copy --quiet &>/dev/null
return 1
end
set -f lines (jj bookmark list --ignore-working-copy --sort committer-date- --quiet --no-pager --color always | grep -v '^[[:space:]]' | grep -v '\(deleted\)' | fzf --cycle --tmux 98% --ansi --layout=reverse \
--scheme=path \
--query="$query" \
--preview='jj log --color=always -r "stack($(echo {} | cut -d: -f2 | awk "{print \\$1}" | string trim))" --no-graph' \
--preview-label='Commit Details' \
--bind='ctrl-y:execute-silent(echo {} | cut -d: -f2 | awk "{print \\$1}" | string trim | pbcopy)' \
--header='Enter: select bookmark, Ctrl-Y: copy revset' \
--border=rounded)
set -l fzf_status $status
if test $fzf_status -eq 0
set -l bookmark (echo $lines | cut -d: -f1 | string trim)
if status is-interactive
commandline --current-token --replace $bookmark
commandline --function repaint
else
echo $bookmark
end
end
return $fzf_status
end

function _fzf-jj-bookmarks --description "Search for jujutsu bookmarks or git branches"
# Change the order here to switch priority
_fzf-jj-bookmarks-jj
set -l status_jj $status
if test $status_jj -eq 0
return 0
else if test $status_jj -ne 1
return $status_jj
end

_fzf-jj-bookmarks-git
set -l status_git $status
if test $status_git -eq 0
return 0
else if test $status_git -ne 1
return $status_git
end

echo "Not in a jj or git repository" >&2
return 1
end

# _fzf-jj-bookmarks
2 changes: 1 addition & 1 deletion conf/fish/funcs/_fzf-jj-revs.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# credit: https://github.com/gessen/fzf.fish/blob/master/functions/_fzf-jj-revs.fish

function _fzf-jj-revs --description "Search for jujutsu revision ids"
jj root --quiet &>/dev/null; or return
jj root --ignore-working-copy --quiet &>/dev/null; or return
set -f lines (jj log --quiet --ignore-working-copy --no-graph --color always \
--revisions 'bookmarks(towry) | (ancestors(@) & author(towry) ~ empty())' \
--template 'committer.timestamp().format("%F/%H:%M") ++ " " ++change_id.shortest(7) ++ " " ++ description.first_line() ++ " " ++ bookmarks ++ "\n"' \
Expand Down
51 changes: 2 additions & 49 deletions conf/fish/funcs/jj-fork-main.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,6 @@ function jj-fork-main --description "Fork main branch"
return 1
end

set -l description $_flag_description
jj git fetch -b main > /dev/null 2>&1
or return

# create bookmark name from aichat
echo "Generating bookmark name..."
set -l bookmark_name (aichat --role git-branch -S -c "$description")
or return

set -l date_now (date +%m%d%H)
set -l bookmark_name "$bookmark_name-$date_now"

# check if the bookmark name is already used
# by running jj log -r $bookmark_name -n 1
# if no error, then the bookmark name is already used
# exit with error msg
jj log -r $bookmark_name -n 1 > /dev/null 2>&1
if test $status -eq 0
echo "Bookmark name $bookmark_name is already used"
return 1
end

# 确保我们能捕获所有输出,包括stderr
set -l output (jj new --no-pager --no-edit -r main@origin -m "$description" 2>&1)
if test $status -ne 0
echo "Failed to create new revision"
return 1
end

# 将输出按行分割,然后在每行中查找commit ID
set -l rev
for line in (string split \n -- $output)
set -l match (string match -r 'Created new commit ([a-z]+)' $line)
if test (count $match) -eq 2
set rev $match[2]
break
end
end

if test -z "$rev"
echo "Failed to extract revision ID from output: $output"
return 1
end

echo "Created new revision: $rev"

echo "Creating bookmark point to $rev: $bookmark_name"
jj bookmark set -r $rev "$bookmark_name"
or return
# Use the generic jj-fork function with main bookmark
jj-fork -d $_flag_description -b main
end
47 changes: 2 additions & 45 deletions conf/fish/funcs/jj-fork-master.fish
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,6 @@ function jj-fork-master --description "Fork master branch"
return 1
end

set -l description $_flag_description
jj git fetch -b master > /dev/null 2>&1
or return

# create bookmark name from aichat
echo "Generating bookmark name..."
set -l bookmark_name (aichat --role git-branch -S -c "$description")
or return

set -l date_now (date +%m%d%H)
set -l bookmark_name "$bookmark_name-$date_now"

jj log --quiet -r $bookmark_name -n 1 > /dev/null 2>&1
if test $status -eq 0
echo "Bookmark name $bookmark_name is already used"
return 1
end

# 确保我们能捕获所有输出,包括stderr
set -l output (jj new --no-pager --no-edit -r master@origin -m "$description" 2>&1)
if test $status -ne 0
echo "Failed to create new revision"
return 1
end

# 将输出按行分割,然后在每行中查找commit ID
set -l rev
for line in (string split \n -- $output)
set -l match (string match -r 'Created new commit ([a-z]+)' $line)
if test (count $match) -eq 2
set rev $match[2]
break
end
end

if test -z "$rev"
echo "Failed to extract revision ID from output: $output"
return 1
end

echo "Created new revision: $rev"

echo "Creating bookmark point to $rev: $bookmark_name"
jj bookmark set -r $rev "$bookmark_name"
or return
# Use the generic jj-fork function with master bookmark
jj-fork -d $_flag_description -b master
end
117 changes: 117 additions & 0 deletions conf/fish/funcs/jj-fork.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# generic jj-fork function
# take arguments -b for bookmark name, -r for revision.
# if -b is provided, run git fetch first
# if -r is provided, run jj new with the revision

function jj-fork --description "Fork from a bookmark or revision"
argparse 'h/help' 'd/description=' 'b/bookmark=' 'r/revision=' 'no-new' -- $argv
or return

# set help string
set -l help_string "Usage: jj-fork -d <description> [-b <bookmark>|-r <revision>] [--no-new]
-d, --description Description for the new revision
-b, --bookmark Bookmark to fork from (will fetch from origin)
-r, --revision Revision to fork from (local revision)
--no-new Create bookmark on existing revision without creating new commit
-h, --help Show this help"

if set -ql _flag_help
echo $help_string
return 0
end

if not set -q _flag_description
echo "Error: Description is required"
echo $help_string
return 1
end

# Ensure either bookmark or revision is provided, but not both
if set -q _flag_bookmark; and set -q _flag_revision
echo "Error: Cannot specify both bookmark and revision"
echo $help_string
return 1
end

if not set -q _flag_bookmark; and not set -q _flag_revision
echo "Error: Must specify either bookmark or revision"
echo $help_string
return 1
end

set -l description $_flag_description
set -l source_ref

# Handle bookmark case - fetch from origin
if set -q _flag_bookmark
set -l bookmark $_flag_bookmark
echo "Fetching bookmark: $bookmark"
jj --ignore-working-copy git fetch -b $bookmark > /dev/null 2>&1
or return
set source_ref "$bookmark@origin"
end

# Handle revision case - use local revision
if set -q _flag_revision
set source_ref $_flag_revision
end

# Generate bookmark name from aichat
echo "Generating bookmark name..."
set -l bookmark_name (aichat --role git-branch -S -c "$description")
or return

set -l date_now (date +%m%d%H)
set -l bookmark_name "$bookmark_name-$date_now"

# Check if the bookmark name is already used
jj --ignore-working-copy log --quiet -r $bookmark_name -n 1 > /dev/null 2>&1
if test $status -eq 0
echo "Bookmark name $bookmark_name is already used"
return 1
end

set -l rev

# If --no-new flag is set, use the source revision directly
if set -q _flag_no_new
echo "Creating bookmark on existing revision $source_ref..."
set rev $source_ref
else
# Create new revision
echo "Creating new revision from $source_ref..."
set -l output (jj new --ignore-working-copy --no-pager --no-edit -r $source_ref -m "$description" 2>&1)
if test $status -ne 0
echo "Failed to create new revision"
echo $output
return 1
end

# Extract revision ID from output
for line in (string split \n -- $output)
set -l match (string match -r 'Created new commit ([a-z]+)' $line)
if test (count $match) -eq 2
set rev $match[2]
break
end
end

if test -z "$rev"
echo "Failed to extract revision ID from output: $output"
return 1
end

echo "Created new revision: $rev"
end

# Create bookmark pointing to the revision
echo "Creating bookmark pointing to $rev: $bookmark_name"
jj bookmark set -r $rev "$bookmark_name"
or return

if set -q _flag_no_new
echo "Successfully created bookmark '$bookmark_name' pointing to existing revision $rev"
else
echo "Successfully created bookmark '$bookmark_name' pointing to revision $rev"
end
end
4 changes: 2 additions & 2 deletions conf/ghostty/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# https://github.com/ghostty-org/ghostty/blob/b8ffee7acbdd5ee97953f6e6d02e047d4bfda37b/src/input/key.zig#L255


theme = dark:dracula,light:dracula
theme = dark:Builtin Pastel Dark,light:Builtin Pastel Light
font-family = "Berkeley Mono"
window-title-font-family = "PT Sans"
font-feature = "+calt"
# font-family = "Maple Mono"
# font-feature = "-zero, +calt, +cv01, +ss03, +ss06, +ss02, -cv35"
font-size = 16
font-size = 17
font-thicken = false
font-codepoint-map = U+4E00-U+9FFF,U+3400-U+4DBF=LXGW WenKai Mono
shell-integration-features = no-cursor,sudo,no-title
Expand Down
Loading