Skip to content

fix: handle exec init to prevent TUI on re-source#105

Open
zzzhizhia wants to merge 2 commits intotobi:mainfrom
zzzhizhia:main
Open

fix: handle exec init to prevent TUI on re-source#105
zzzhizhia wants to merge 2 commits intotobi:mainfrom
zzzhizhia:main

Conversation

@zzzhizhia
Copy link

@zzzhizhia zzzhizhia commented Mar 15, 2026

Summary

Fix 1: Handle exec init subcommand

  • When re-sourcing ~/.zshrc, the try shell function is already defined, so try init ~/path routes through the wrapper as try exec init ~/path
  • The exec handler didn't have a case for init, causing it to fall through to the default TUI selector — triggering an unwanted interactive UI with search term init-/path/to/tries
  • Added when 'init' to the exec subcommand dispatch so it correctly delegates to cmd_init!
  • Added regression test in spec/tests/test_03_commands.sh

Fix 2: Invoke script directly instead of via /usr/bin/env ruby

  • The init shell function used /usr/bin/env ruby to invoke the script, which could resolve to the wrong Ruby version (e.g. system Ruby 2.6 lacking Data.define support)
  • Changed to invoke the script path directly, letting the shebang determine which Ruby to use
  • script_path is always File.expand_path($0) — the absolute path of the running script — so direct invocation is safe
  • Applied to all three shell snippets: bash/zsh, fish, and PowerShell

Reproduce

# In ~/.zshrc:
eval "$(try init ~/Developer/tries)"

# First source works fine, second triggers TUI:
source ~/.zshrc  # ← interactive selector pops up

Test plan

  • try init ~/path still outputs shell function definition
  • try exec init ~/path now also outputs shell function definition (instead of opening TUI)
  • source ~/.zshrc can be run multiple times without triggering the selector
  • Init snippet no longer contains /usr/bin/env ruby, uses script path directly

When re-sourcing ~/.zshrc, the `try` shell function is already defined,
so `try init` routes through the wrapper as `try exec init`. The exec
handler didn't have a case for `init`, causing it to fall through to
the TUI selector. Add `when 'init'` to the exec subcommand dispatch.
Copilot AI review requested due to automatic review settings March 15, 2026 05:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where re-sourcing ~/.zshrc (when the try shell function is already defined) causes try init ~/path to be routed as try exec init ~/path, which previously fell through to the default TUI selector instead of outputting the shell function definition.

Changes:

  • Added a when 'init' case to the exec subcommand dispatch in try.rb to correctly delegate to cmd_init!
  • Added a regression test verifying exec init outputs the shell function

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
try.rb Added init handling in the exec case to delegate to cmd_init!
spec/tests/test_03_commands.sh Added regression test for exec init outputting the shell function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The init shell function used `/usr/bin/env ruby` to invoke the script,
which could resolve to the wrong Ruby version (e.g. system Ruby 2.6
lacking Data.define support). Invoke the script path directly and let
the shebang determine which Ruby to use.

`script_path` is always `File.expand_path($0)` — the absolute path of
the running script — so direct invocation via shebang is safe. Applied
to all three shell snippets: bash/zsh, fish, and PowerShell.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants