fix: handle exec init to prevent TUI on re-source#105
Open
fix: handle exec init to prevent TUI on re-source#105
exec init to prevent TUI on re-source#105Conversation
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.
There was a problem hiding this comment.
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 theexecsubcommand dispatch intry.rbto correctly delegate tocmd_init! - Added a regression test verifying
exec initoutputs 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix 1: Handle
exec initsubcommand~/.zshrc, thetryshell function is already defined, sotry init ~/pathroutes through the wrapper astry exec init ~/pathexechandler didn't have a case forinit, causing it to fall through to the default TUI selector — triggering an unwanted interactive UI with search terminit-/path/to/trieswhen 'init'to theexecsubcommand dispatch so it correctly delegates tocmd_init!spec/tests/test_03_commands.shFix 2: Invoke script directly instead of via
/usr/bin/env ruby/usr/bin/env rubyto invoke the script, which could resolve to the wrong Ruby version (e.g. system Ruby 2.6 lackingData.definesupport)script_pathis alwaysFile.expand_path($0)— the absolute path of the running script — so direct invocation is safeReproduce
Test plan
try init ~/pathstill outputs shell function definitiontry exec init ~/pathnow also outputs shell function definition (instead of opening TUI)source ~/.zshrccan be run multiple times without triggering the selector/usr/bin/env ruby, uses script path directly