script-commands icon indicating copy to clipboard operation
script-commands copied to clipboard

Unable to use path with spaces in shebang flags

Open noahbald opened this issue 1 year ago • 3 comments

Hi there, when attempting to provide a path via shebang I'm unable to effectively pass a flag with a space in it.

The following shebangs do not work

Using a string

#!/opt/homebrew/bin/nu --env-config "~/Library/Application Support/nushell/env.nu"

Results in the following error

Error: nu::parser::file_not_found

  × File not found
   ╭─[source:1:17]
 1 │ nu --env-config "\"~/Library/Application"
   ·                 ────────────┬────────────
   ·                             ╰── File not found: "~/Library/Application
   ╰────

Error: nu::shell::file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ nu --env-config "\"~/Library/Application"
   · ▲
   · ╰── Could not access file 'Support/nushell/env.nu"': No such file or directory (os error 2)
   ╰────

Escaping spaces

#!/opt/homebrew/bin/nu --env-config ~/Library/Application\ Support/nushell/env.nu

Results in the following error

Error: nu::parser::file_not_found

  × File not found
   ╭─[source:1:17]
 1 │ nu --env-config "~/Library/Application\\"
   ·                 ────────────┬────────────
   ·                             ╰── File not found: ~/Library/Application\
   ╰────

Error: nu::shell::file_not_found

  × File not found
   ╭─[source:1:1]
 1 │ nu --env-config "~/Library/Application\\"
   · ▲
   · ╰── Could not access file 'Support/nushell/env.nu': No such file or directory (os error 2)
   ╰────

Workarounds

  • Use a symlink

noahbald avatar Sep 11 '24 00:09 noahbald

Hi @noahbald, Maybe you've read the Troubleshooting and FAQs, in there, you can find this:

Can I build in a non-login shell?

We only allow Script Commands that run in a non-login shell in this repository as agreed on in our contribution guidelines, due to any dependencies. However, if you need to run your local script as login-shell, you can specify an argument after shebang, e.g. #!/bin/bash -l for bash. We also append /usr/local/bin to $PATH variable so you can use your local shell commands without any additional steps. If this is not enough, you can always extend $PATH by adding export PATH='/some/extra/path:$PATH' at the top of your script.

I am showing you this just to tell you that Raycast runs in a non-login environment, which is surely causing the problem you are facing. Also, in that message, you can read about two solutions.

Give it a check, and write back in case the problem remains.

unnamedd avatar Sep 11 '24 13:09 unnamedd

Hey @unnamedd I did have a look through troubleshotting and I think this is a bug with Raycast rather than whether or not I'm using a login shell.

The cause of my problem seems to be with how the shebang is being parsed.

you can specify an argument after shebang

My thinking was we can use any sort of arguments for whichever shell/application we wish to invoke. I'm trying to invoke nushell (rather than bash) and, in this particular case, I wish to pass it a specific path.

The issue is, however, anything separated by a space seems to be treated as a seperate argument, regardless of whether that space is escaped (i.e \ ) or contained within a string (e.g "foo bar")

noahbald avatar Sep 12 '24 01:09 noahbald

Hey @noahbald

Does the script work executing it outside Raycast? Meaning just in the terminal with ./nameOfScript. I say this, because we don't do any special parsing of the shebang, we just pass it along to the Foundation's Process object. You can see the code here.

dehesa avatar Sep 13 '24 13:09 dehesa

Ah yes, looks like it fails when runnin ./nameOfScript. Perhaps it's an issue with nushell I can raise an issue with. Thank you :)

noahbald avatar Sep 16 '24 02:09 noahbald