multiple worktree creation

This commit is contained in:
2026-06-19 16:02:06 +02:00
parent b8a4f52609
commit 4e2ed7f99f
4 changed files with 33 additions and 7 deletions

View File

@@ -30,6 +30,7 @@ public record AppConfig(
boolean kittyGraphics,
String scrollbackEditorCommand,
String worktreeRelativePath,
String worktreeSplitRegex,
String closeSignal,
Map<String, String> envOverride,
Map<String, KeyBinding> keybindings
@@ -77,6 +78,7 @@ public record AppConfig(
booleanValue(document, "kitty_graphics.enabled", defaults.kittyGraphics),
stringValue(document, "scrollback.editor_command", defaults.scrollbackEditorCommand),
stringValue(document, "worktree.relative_worktree_path", defaults.worktreeRelativePath),
stringValue(document, "worktree.split_regex", defaults.worktreeSplitRegex),
closeSignalValue(document, defaults.closeSignal),
envOverride(document, defaults.envOverride),
keybindings(document, defaults)
@@ -100,6 +102,7 @@ public record AppConfig(
true,
defaultScrollbackEditorCommand(),
"./.worktrees",
",",
"SIGTERM",
Map.of(),
Map.ofEntries(
@@ -138,6 +141,7 @@ public record AppConfig(
kittyGraphics,
scrollbackEditorCommand,
worktreeRelativePath,
worktreeSplitRegex,
closeSignal,
envOverride,
keybindings
@@ -241,7 +245,8 @@ public record AppConfig(
builder.append("[scrollback]\n");
builder.append("editor_command = ").append(quoted(scrollbackEditorCommand)).append("\n\n");
builder.append("[worktree]\n");
builder.append("relative_worktree_path = ").append(quoted(worktreeRelativePath)).append("\n\n");
builder.append("relative_worktree_path = ").append(quoted(worktreeRelativePath)).append('\n');
builder.append("split_regex = ").append(quoted(worktreeSplitRegex)).append("\n\n");
builder.append("[env.override]\n");
for (Map.Entry<String, String> entry : envOverride.entrySet()) {
builder.append(entry.getKey()).append(" = ").append(quoted(entry.getValue())).append('\n');

View File

@@ -313,14 +313,32 @@ final class TerminalWindow {
if (relativePath == null || relativePath.isBlank()) {
relativePath = "./.worktrees";
}
String splitRegex = config.worktreeSplitRegex();
if (splitRegex == null || splitRegex.isBlank()) {
splitRegex = ",";
}
return editorCommand(file)
+ "; editor_status=$?"
+ "; name=$(cat " + quotedFile + ")"
+ "; if [ \"$editor_status\" -eq 0 ] && [ -n \"$name\" ]; then"
+ "; git_status=$editor_status"
+ "; if [ \"$editor_status\" -eq 0 ]; then"
+ " if names_file=$(mktemp); then"
+ " if awk -v re=" + shellQuote(splitRegex)
+ " '{ text = text $0 \"\\n\" }"
+ " END { n = split(text, names, re); for (i = 1; i <= n; i++)"
+ " { name = names[i]; sub(/^[[:space:]]+/, \"\", name);"
+ " sub(/[[:space:]]+$/, \"\", name); if (name != \"\") print name; } }'"
+ " " + quotedFile + " > \"$names_file\"; then"
+ " git_status=0"
+ "; while IFS= read -r name; do"
+ " git worktree add " + shellQuote(relativePath) + "/\"$name\""
+ "; git_status=$?"
+ "; else git_status=$editor_status"
+ " || { git_status=$?; break; }"
+ "; done < \"$names_file\""
+ "; else git_status=$?"
+ "; fi"
+ "; rm -f \"$names_file\""
+ "; else git_status=$?"
+ "; fi"
+ "; fi"
+ "; rm -f " + quotedFile
+ "; exit \"$git_status\"";