`try init` returns bash syntax under fish when $SHELL is not fish
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 4k
- Forks
- 159
- PR merge metrics
- No merged PRs in 30d
Description
What happens
I use fish, but my login shell is zsh, so $SHELL is /bin/zsh. try init returns the bash function instead of the fish function. The README line then fails:
❯ try init "$HOME/tries" | source
- (line 1): command substitutions not allowed in command position. Try var=(your-cmd) $var ...
try() {
^^
from sourcing file -
source: Error while reading file '<stdin>'
Cause
cmd_init! picks the syntax with fish? (try.rb:1281 on main):
shell = fish? ? 'fish' : 'bash'
fish? reads $SHELL first (try.rb:1646):
def fish?
shell = ENV["SHELL"].to_s
if shell.empty?
shell = (`ps c -p #{Process.ppid} -o 'ucomm='`.strip rescue "").to_s
end
shell.include?('fish')
end
The parent process check runs only when $SHELL is empty. $SHELL holds the login shell, not the shell that runs the command. Any user who starts fish from a different login shell gets bash syntax.
The existing fallback already works
The parent process check detects fish correctly. It is only unreachable. With $SHELL removed, try init returns the fish function:
❯ env -u SHELL try init "$HOME/tries" | head -2
function try
set -l out (/usr/bin/env ruby '.../try.rb' exec --path '/Users/samedwardes/tries' $argv 2>/dev/tty | string collect)
This also works through the Homebrew wrapper at /opt/homebrew/bin/try. The wrapper uses exec, so the Ruby process keeps fish as its parent.
Suggested fix
Check the parent process first in fish?, then fall back to $SHELL. The parent process is the shell that reads the output of try init.
A --shell flag on try init would also help. It makes the choice explicit and testable.
detect_shell (try.rb:1331), which try install uses, has the same $SHELL-first order. Reading $SHELL there is defensible, because install writes to the rc file of the login shell.
Workaround
env SHELL=(status fish-path) try init "$HOME/tries" | source
Environment
- try 1.10.1 (Homebrew). Confirmed on
mainat try.rb:1281 and try.rb:1646. - fish 4.8.1
- macOS 26.6.2, Apple Silicon
$SHELL=/bin/zsh, login shell zsh
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in try.rb at cmd_init! around line 1281 and fish? around line 1646; inspect how shell detection chooses between fish and bash. Run try init from fish with $SHELL set to zsh, then repeat with $SHELL unset to compare the generated output. Done means the command selects fish syntax based on its parent shell while preserving the existing fallback behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, fish, ruby, shell, zsh
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100