Skip to content
Open
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
8 changes: 8 additions & 0 deletions spec/tests/test_03_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ else
fail "exec clone should include cd" "contains cd command" "$output" "command_line.md#clone"
fi

# Test: exec init outputs shell function (regression: re-sourcing .zshrc)
output=$(try_run --path="$TEST_TRIES" exec init "$TEST_TRIES" 2>&1)
if echo "$output" | grep -q "try()"; then
pass
else
fail "exec init should output shell function" "contains 'try()'" "$output" "command_line.md#init"
fi

# Test: exec cd is equivalent to exec (default command)
output1=$(try_run --path="$TEST_TRIES" --and-keys=$'\r' exec 2>/dev/null)
output2=$(try_run --path="$TEST_TRIES" --and-keys=$'\r' exec cd 2>/dev/null)
Expand Down
9 changes: 6 additions & 3 deletions try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ def init_snippet(shell, script_path, explicit_path, default_path)
fish_path_arg = explicit_path ? " --path '#{explicit_path}'" : " --path (if set -q TRY_PATH; echo \"$TRY_PATH\"; else; echo '#{default_path}'; end)"
<<~FISH
function try
set -l out (/usr/bin/env ruby '#{script_path}' exec#{fish_path_arg} $argv 2>/dev/tty | string collect)
set -l out ('#{script_path}' exec#{fish_path_arg} $argv 2>/dev/tty | string collect)
if test $pipestatus[1] -eq 0
eval $out
else
Expand All @@ -1286,7 +1286,7 @@ def init_snippet(shell, script_path, explicit_path, default_path)
function try {
$tryPath = #{ps_path_expr}
$tempErr = [System.IO.Path]::GetTempFileName()
$out = & ruby '#{script_path}' exec --path $tryPath @args 2>$tempErr
$out = & '#{script_path}' exec --path $tryPath @args 2>$tempErr
if ($LASTEXITCODE -eq 0) {
$out | Invoke-Expression
} else {
Expand All @@ -1301,7 +1301,7 @@ def init_snippet(shell, script_path, explicit_path, default_path)
<<~SH
try() {
local out
out=$(/usr/bin/env ruby '#{script_path}' exec#{path_arg} "$@" 2>/dev/tty)
out=$('#{script_path}' exec#{path_arg} "$@" 2>/dev/tty)
if [ $? -eq 0 ]; then
eval "$out"
else
Expand Down Expand Up @@ -1541,6 +1541,9 @@ def worktree_path(tries_path, repo_dir, custom_name)
when 'clone'
ARGV.shift
emit_script(cmd_clone!(ARGV, tries_path))
when 'init'
ARGV.shift
cmd_init!(ARGV, tries_path)
when 'worktree'
ARGV.shift
repo = ARGV.shift
Expand Down