randy3k / Terminus

Bring a real terminal to Sublime Text
https://packagecontrol.io/packages/Terminus
MIT License
1.37k stars 83 forks source link

Running a command the contains `**` is interpreted incorrectly #332

Closed timfjord closed 2 years ago

timfjord commented 2 years ago

I've been trying to run the following command in Terminus

{ 
  "command": "terminus_open", 
  "args": {
    "cwd": "${folder}",
    "shell_cmd": "bundle exec ruby -Itest  test/**/*_test.rb"
  }
}

and it's been always giving me

Traceback (most recent call last):
/Users/timfjord/.rubies/ruby-2.7.2/bin/ruby: No such file or directory -- test/**/*_test.rb (LoadError)
process is terminated with return code 1.

I can successfully run this command in a native terminal(iTerm 2 in my case). I have a feeling that it is somehow related to the double splat(either the double splat itself or a combination of the / and **, like /** or **/) and the way Terminus(or the low-level libraries) interprets that, because bundle exec ruby -Itest test/*_test.rb(without the **) works great. Maybe it quotes the argument, I don't know, because I can achieve the same output in the native terminal if I wrap the argument in the quotes (bundle exec ruby -Itest 'test/**/*_test.rb')

I couldn't find anything related to that in the Terminus source code so maybe there are some well-know limitations

randy3k commented 2 years ago

I bet that you are using zsh in iTerm.

The main reason of the failure is that Terminus uses bash to run shell_cmd and bash doesn't expand ** in default (there is a setting globstar to control it). OTOH, zsh has it enabled in default.

To explain why quotation works, I guess the quoted input is passed to ruby directly without expansion and ruby knows that it was quoted and tries to expand it.

timfjord commented 2 years ago

Thanks for the tip @randy3k Indeed, I am on zsh and, as you mentioned, when I tried that in bash it didn't work. It can be enabled with the shopt -s globstar for Bash 4+, but I think I've found a workaround that can be used even for older versions of Bash, basically something like find test -name "*_test.rb" -exec bundle exec ruby -Itest {} +

Closing the issue as it has nothing to do with Terminus