Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A different syntax for set shell? #1190

Closed
frederikhors opened this issue May 17, 2022 · 14 comments
Closed

A different syntax for set shell? #1190

frederikhors opened this issue May 17, 2022 · 14 comments

Comments

@frederikhors
Copy link

frederikhors commented May 17, 2022

Thinking about it better, even after #1185, I thought that perhaps the way to indicate the shell should be revised.

I'll explain.

On Windows you have arbitrarily chosen to use sh.exe (which was installed on my system when I installed Git).

It is a shell that is used by Git for git-bash.exe.

In my projects I'll have many justfile used by many people on Windows, Linux and Mac.

Right now I don't have a set shell := ... command in the justfile and I'm using many times in recipes the conditional string: {{if os_family() == "windows" { "pwsh.exe -c" } else { "" } }} before the command if that command doesn't work in sh.exe (and works perfectly on pwsh.exe (I'm not using in that case a bash syntax)).

Now I'm writing recipes which use commands like npm run build or npm install and I don't know why but I'm having hard times making it work because in my system sh.exe cannot run npm (the PC has just been installed, everything works good, nodejs 16 LTS):

npm i
/bin/bash: C:/Program Files/nodejs/npm: No such file or directory

I don't have time to further investigate and I don't want too because things need to work on my co-worker PCs too...

Another problem with sh.exe are the exit codes from CLI like the heroku's one and similar made in nodejs. The exit codes are always 1 even if the commands correctly worked.

So...

THE REQUEST/QUESTION

Can we have a different set shell syntax like the one I'm using on each problematic command?

Example:

set shell := {{ if os_family() == "windows" { "pwsh.exe -c" } else { "bash" } }}

What do you think?

Basically: I need to have a universal justfile that can be used on all operating systems.

@hustcer
Copy link
Contributor

hustcer commented May 17, 2022

Maybe my reply is off topic:
I'd recommend you use a cross platform shell, like nushell: https://www.nushell.sh/ as a workaround
That's what am I doing

@frederikhors
Copy link
Author

How you use it?

Can you use the same set shell := command if you launch justfile in a CI pipeline?

@frederikhors
Copy link
Author

How you use it?

With the justfile I mean.

@hustcer
Copy link
Contributor

hustcer commented May 17, 2022

Nushell works on mac, Linux and windows so set shell := ['nu', '-c'] is enough, here is a example for you:
https://github.com/hustcer/setup-nu/blob/main/Justfile
I haven't use just in a CI pipeline, if you want to use just and nushell in CI pipeline maybe you need:

  1. https://github.com/hustcer/setup-nu to setup nushell
  2. and https://github.com/extractions/setup-crate to setup just

@casey
Copy link
Owner

casey commented May 17, 2022

This is kind of what set windows-powershell is for. Since many sh-isms work under powershell, it is a decent way of writing cross-platform justfiles.

@frederikhors
Copy link
Author

Ok. I'm waiting for set windows-pwsh then.

@frederikhors
Copy link
Author

frederikhors commented May 22, 2022

@casey sorry for the ping here, just to ask if set windows-pwsh change will take a long time or a short time.

Using sh.exe on Windows is very limiting and sometimes there are strange behaviors.

@casey
Copy link
Owner

casey commented May 28, 2022

@frederikhors Hard to say! I'm pretty busy with other projects, so I can't give a timeline for anything.

I was thinking that perhaps, instead of providing a windows-pwsh setting to enable pwsh.exe, it would be better to add a windows-shell setting that takes a shell and arguments. I opened a PR with the implementation here:

#1198

To use it, you would do:

set windows-shell := ["pwsh.exe", "-NoLogo", "-Command"]

foo:
  Write-Output bar

Not only does this allow using pwsh.exe on Windows, but you could also pick a different shell, or different arguments for windows, instead of being limited to one chosen by me.

cc: @runeimp What do you think?

@frederikhors
Copy link
Author

it would be better to add a windows-shell setting

I agree! Thanks!

@casey
Copy link
Owner

casey commented May 28, 2022

I added a user feedback thread, locked so it's low-spam if you subscribe, here: #1202

There's a bit of commentary about this change. I'll probably let it sit for a few days and see if anyone has anything to say, since I'm always nervous I'll mess something up with Windows, but otherwise it's good to go.

@frederikhors
Copy link
Author

Subscribed. Thanks. I’ll use windows unfortunately for the next months, so I can give you good hints on it.

@casey
Copy link
Owner

casey commented May 31, 2022

This is done and released as of 1.2.0, set windows-shell can be used to control the shell on Windows.

@casey casey closed this as completed May 31, 2022
@frederikhors
Copy link
Author

I have tried your new feature and it works great! Thanks!

Unfortunately since I opened the issue the justifle has grown dramatically and today I find myself with a lot of code partly executed on "sh.exe" and partly executed on "pwsh.exe" (because on "sh.exe" executables like "heroku" or "npm" do not work!).

Today I tried to run with set windows-shell and I realized how many commands I had to change to use it.

Incredible!

So I think I'll not use set windows-shell and instead I will stick with:

{{if os_family() == "windows" { "pwsh.exe -c" } else { "" } }} heroku some_command

It would be great to have a short form prefix to the command, like:

backup:
  !windows heroku some_command
  !unix heroku some_other

but I don't want to take away any more your time with another request.

If you want I can open an issue for this, but only if you want.

Congratulations again on what you are doing!

@runeimp
Copy link

runeimp commented Jun 18, 2022

Interesting addition @casey ! But, most likely the best cross platform options are just using Nushell if you lean towered the POSIX side of shell scripting or PowerShell if you lean towards the Windows side. As noted by @hustcer Nushell runs on Linux, macOS, and Windows. PowerShell is also available for Linux, macOS, and Windows now. There will always be logic situations that require extra coding depending on if you're on Windows or not but one of those two options will at least give you consistent flow control logic, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants