diff --git a/spec/tests/test_03_commands.sh b/spec/tests/test_03_commands.sh index 36ce057..021d7b7 100644 --- a/spec/tests/test_03_commands.sh +++ b/spec/tests/test_03_commands.sh @@ -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) diff --git a/try.rb b/try.rb index d966f80..9b46547 100755 --- a/try.rb +++ b/try.rb @@ -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 @@ -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 { @@ -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 @@ -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