Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Fix: Remove TODOs and simplify shell scripts

Maximilian Roos100a55aba28f
diff --git a/templates/nushell.nu b/templates/nushell.nu
index c53d1541a..136469483 100644
--- a/templates/nushell.nu
+++ b/templates/nushell.nu
@@ -17,13 +17,11 @@ if (which wt | is-not-empty) or ($env.WORKTRUNK_BIN? | is-not-empty) {
for chunk in ($result.stdout | split row "\u{0000}") {
if ($chunk | str starts-with "__WORKTRUNK_CD__") {
# CD directive - extract path and change directory
- # TODO: Use str replace instead of hard-coded offset (fragile if prefix changes)
- let path = ($chunk | str substring 16..)
+ let path = ($chunk | str replace --regex '^__WORKTRUNK_CD__' '')
cd $path
} else if ($chunk | str starts-with "__WORKTRUNK_EXEC__") {
# EXEC directive - extract command (may contain newlines)
- # TODO: Use str replace instead of hard-coded offset (fragile if prefix changes)
- $exec_cmd = ($chunk | str substring 18..)
+ $exec_cmd = ($chunk | str replace --regex '^__WORKTRUNK_EXEC__' '')
} else if ($chunk | str length) > 0 {
# Regular output - print it with newline
print $chunk
diff --git a/templates/powershell.ps1 b/templates/powershell.ps1
index 0233bee0d..7eb879240 100644
--- a/templates/powershell.ps1
+++ b/templates/powershell.ps1
@@ -35,8 +35,7 @@ if ((Get-Command wt -ErrorAction SilentlyContinue) -or $env:WORKTRUNK_BIN) {
$execCmd = $chunk -replace '^__WORKTRUNK_EXEC__', ''
} elseif ($chunk) {
# Regular output - write it with newline
- # TODO: Use Write-Output instead of Write-Host for redirectable output
- Write-Host $chunk
+ Write-Output $chunk
}
}
diff --git a/templates/xonsh.xsh b/templates/xonsh.xsh
index e3ff86a72..6df60a7cd 100644
--- a/templates/xonsh.xsh
+++ b/templates/xonsh.xsh
@@ -23,13 +23,11 @@ if shutil.which("wt") is not None or os.environ.get('WORKTRUNK_BIN'):
for chunk in result.out.split("\0"):
if chunk.startswith("__WORKTRUNK_CD__"):
# CD directive - extract path and change directory
- # TODO: Use str.replace instead of hard-coded offset (fragile if prefix changes)
- path = chunk[16:] # Remove prefix
+ path = chunk.replace("__WORKTRUNK_CD__", "", 1)
cd @(path)
elif chunk.startswith("__WORKTRUNK_EXEC__"):
# EXEC directive - extract command (may contain newlines)
- # TODO: Use str.replace instead of hard-coded offset (fragile if prefix changes)
- exec_cmd = chunk[18:] # Remove prefix
+ exec_cmd = chunk.replace("__WORKTRUNK_EXEC__", "", 1)
elif chunk:
# Regular output - print it with newline
print(chunk)
@@ -38,9 +36,8 @@ if shutil.which("wt") is not None or os.environ.get('WORKTRUNK_BIN'):
if exec_cmd:
execx(exec_cmd)
- # Return the exit code
- # TODO: Add fallback for None: return result.returncode or 0
- return result.returncode
+ # Return the exit code, defaulting to 0 if the subprocess did not set one
+ return result.returncode if result.returncode is not None else 0
def _{{ cmd_prefix }}_wrapper(args):
"""Override {{ cmd_prefix }} command to add --internal flag"""