Problems with shebang and running proper version of ruby with asdf.

44 views
Skip to first unread message

Christopher Waterman

unread,
Aug 9, 2025, 8:38:24 PMAug 9
to BBEdit Talk
I manage my versions of Ruby with asdf.

I have a test script.

#!/usr/bin/env ruby
puts RUBY_VERSION
puts ENV['PATH']

When I use the !# > Run command I get these results:

2.6.10
/usr/local/bin:/usr/local/sbin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/go/bin:/Users/chris/.asdf/shims


That is the system ruby not the one a have set through asdf.
When I remove the shebang line from the script I get:

2.7.4
/Users/chris/.asdf/installs/ruby/2.7.4/bin:/Users/chris/.asdf/installs/ruby/2.7.4/lib/ruby/gems/.0/bin:/Users/chris/.asdf/shims:/usr/local/bin:/usr/local/sbin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/go/bin:/Applications/iTerm.app/Contents/Resources/utilities


This is the result I expect. It is also the result I get if I run the script from the terminal running zsh as my shell.

It's my understanding that BBEdit uses your shell's configuration when the shebang is available but makes it's best guess when it isn't.  Am I correct?

This is my .zprofile 

export PATH="${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"
eval "$(direnv hook zsh)"
export DIRENV_LOG_FORMAT=""
export JRUBY_OPTS="$JRUBY_OPTS -J-XstartOnFirstThread"


Does anyone else use asdf and ruby who can replicate this result? 
Have you had a similar issue? 
Any advice on how I might track this down?

Or am I off base and these are the expected results? 

I'm working a a preview filter and it will only use the system version of ruby and that won't work for what I'm doing.

Allen Hancock

unread,
Aug 11, 2025, 11:42:31 PMAug 11
to bbe...@googlegroups.com
I feel like asdf is only going to spring to action when it sees a .tools-versions (or .ruby-version if you have it set to look for that) in the CWD.
Does your preview filter explicitly set a home directory?

(That's my only idea, as I haven't played with asdf in relation to BBEdit, or created any preview filters)

--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/bbedit/17ec14fb-89c4-4b2a-aa9f-ed9474a53d8dn%40googlegroups.com.

Christopher Waterman

unread,
Aug 16, 2025, 6:40:59 PMAug 16
to BBEdit Talk

My old man loved to say "Assume make an ass out of u and me".

I missunderstood the BBEdit manual and Bare Bones tech support.

I thought the 'Run' command used "the" default shell on your system, but it in fact uses "your" default shell. I was looking in the wrong place for the problem. Though I have ZSH configured I use Fish. 

The asdf website provides this code to add add to your fish config file.
------------------------------------------------------
# ASDF configuration code
if test -z $ASDF_DATA_DIR
    set _asdf_shims "$HOME/.asdf/shims"
else
    set _asdf_shims "$ASDF_DATA_DIR/shims"
end

# Do not use fish_add_path (added in Fish 3.2) because it
# potentially changes the order of items in PATH
if not contains $_asdf_shims $PATH
    set -gx --prepend PATH $_asdf_shims
end
set --erase _asdf_shims

------------------------------------------------------

What I discovered is that the second conditional fails as $_asdf_shims (the asdf shims directory) is present. It's just at the end rather then the beginning when running through BBEdit. This if statement stops  you from getting multiple entries in your path.

I changed my config to look like this.
------------------------------------------------------
# ASDF configuration code
if test -z $ASDF_DATA_DIR
    set _asdf_shims "$HOME/.asdf/shims"
else
    set _asdf_shims "$ASDF_DATA_DIR/shims"
end

# Do not use fish_add_path (added in Fish 3.2) because it
# potentially changes the order of items in PATH
if not contains $_asdf_shims $PATH
    set -gx --prepend PATH $_asdf_shims
end

if string match -q -r "BBEDIT_PID" (env)
fish_add_path -m $_asdf_shims
end

set --erase _asdf_shims
------------------------------------------------------

The expression "fish_add_path -m $_asdf_shims" will reorder $PATH so that $_asdf_shims loads first.
👍

If anyone thinks this could cause me any grief, please let me know.

Reply all
Reply to author
Forward
0 new messages