script-commands
script-commands copied to clipboard
Unable to use path with spaces in shebang flags
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
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.
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")
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.
Ah yes, looks like it fails when runnin ./nameOfScript. Perhaps it's an issue with nushell I can raise an issue with. Thank you :)