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

Support built-in shell commands for an improved Windows support #197

Open
lunny opened this issue Apr 12, 2019 · 11 comments
Open

Support built-in shell commands for an improved Windows support #197

lunny opened this issue Apr 12, 2019 · 11 comments
Labels
dep: mvdan/sh Issues related to the upstream interpreter used by Task. help wanted Issues that could benefit from members of the community contributing their expertise or experience. type: feature A new feature or functionality.

Comments

@lunny
Copy link

lunny commented Apr 12, 2019

For cross-platform usage, some built-in commands will helpful.

@andreynering andreynering added the type: feature A new feature or functionality. label Apr 13, 2019
@andreynering andreynering changed the title Built-in commands Support built-in shell commands for an improved Windows support Apr 13, 2019
@andreynering
Copy link
Member

Hi @lunny,

So, this is something that was discussed before, and I actually wanted to solve this from the beginning, but it requires a considerable amount of work.

You may want to take a look at mvdan/sh#93 and mvdan/sh#97.

In short, it requires someone to implement these built-ins on the https://github.com/mvdan/sh project to make them work on Windows.

It was also discussed before to just use https://github.com/ericlagergren/go-coreutils, but most of these implementations are done on a main package, and thus require work before being able to be imported on https://github.com/mvdan/sh.

If anyone reading this issue is willing to help, let me know. Just make sure to sync with the author on mvdan/sh#93 before starting anything.

@andreynering
Copy link
Member

Just found the issue I was looking for: ericlagergren/go-coreutils#114

@ghost
Copy link

ghost commented Apr 19, 2019

I wonder if this is also useful ?
https://github.com/u-root/u-root

You can inject what commands you want via a template approach too:
https://github.com/u-root/u-root/blob/master/templates.go

@ghost
Copy link

ghost commented Apr 19, 2019

Or cant we use the ones from Mage ? as a base ?

@andreynering
Copy link
Member

Hi @gedw99,

I wonder if this is also useful? https://github.com/u-root/u-root

Hmm... interesting project. It definitely have some core tools implemented. Would still require work, though, since these tools are main package (so, not importable).

Or cant we use the ones from Mage?

Mage fallsback to system tools just like Tusk.

@andreynering andreynering added the help wanted Issues that could benefit from members of the community contributing their expertise or experience. label Aug 4, 2021
@andreynering andreynering added the dep: mvdan/sh Issues related to the upstream interpreter used by Task. label Sep 6, 2021
@bigBron
Copy link

bigBron commented Feb 28, 2023

So, it's 2023 now, and there's no news?

@nathanblair
Copy link

I found, as a workaround for the absolute most trivial use case of reading a file, which I would usually reach to cat for, there is more that works in cmd on Windows and should be pretty cross-distro for UNIX-like systems.

e.g.

vars:
  VARIABLE:
    sh: more "{{.FILE_TO_READ_INTO_VARIABLE}}"

and that seems to populate the variable for Windows, macOS, and Linux (an Alpine instance).

Still would love a more stable API, but this is one case that's common that I wouldn't know another easy solution without hacking together a {{if}} {{else}} template.

@JohnHardy
Copy link

Hey @andreynering, since it's been a while it might be worth a note in the docs?

For example, in Platform specific tasks and commands we could say:

Writing fully cross platform tasks can still be difficult because not all shells work in the same way (e.g. `cp`, `mv`, `mkdir`, etc are different or have different names).

* [Use a specific shell](https://github.com/go-task/task/issues/892#issuecomment-1278217185) in the task script.
* Use [alternative implementations](https://gnuwin32.sourceforge.net/packages/coreutils.htm) of core utils or a specific shell on Windows like [git bash](https://gitforwindows.org/).
* Use [OS specific](https://taskfile.dev/usage/#os-specific-taskfiles) scripts.
* [Contribute](https://github.com/mvdan/sh/issues/93) to Task!

REF: mvdan/sh#93

@JohnHardy
Copy link

JohnHardy commented Sep 18, 2023

Another approach could be to specify the required shell in the taskfile, so workarounds are more intentional and fail gracefully if the task can't execute. Similar to the shopt or platforms control that already exists.

We could also clean up the {{.SHELL}} workaround that makes the tasks hard to read.

vars:
  SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}{{if eq .OS "darwin"}}pwsh{{end}}'

  clean:
    cmds:
      - '{{.SHELL}} rm -r ./builds/'
      - '{{.SHELL}} rm -r ./packs/'

Would, for instance, become:

shell:
    windows: powershell
    darwin: pwsh

  clean:
    cmds:
      - rm -r ./builds/
      - rm -r ./packs/

@leaanthony
Copy link
Contributor

leaanthony commented Sep 24, 2023

If there's support among us for built-in commands, I can help out. By built-in commands, I mean using something like this, instead of flaky shelling:

  clean:
    cmds:
      - rmdir: ./builds/
      - rm: ./packs/file.go
      - cp: ./packs-backup/file.go ./packs/file.go
      - mv: ./backup/manifest.xml ./site/

@JohnHardy
Copy link

I personally like it!

I dare say it would be easy enough to find the most commonly used parameters to avoid it becoming a shell replacement: https://discord.com/channels/974121106208354339/1025054680289660989/threads/1028716829981544559

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dep: mvdan/sh Issues related to the upstream interpreter used by Task. help wanted Issues that could benefit from members of the community contributing their expertise or experience. type: feature A new feature or functionality.
Projects
None yet
Development

No branches or pull requests

6 participants