MSYS2-packages icon indicating copy to clipboard operation
MSYS2-packages copied to clipboard

msystem.bat

Open userzimmermann opened this issue 8 years ago • 9 comments

Hi. I want to contribute msystem.bat from my Chocolatey MSYS2 package:

https://github.com/userzimmermann/choco-packages/blob/master/msys2/msystem.bat

It activates and switches MSYS, MINGW32, and MINGW64 environments directly in CMD shell, by prepending the according *bin* paths to %PATH% and adding tags to %PROMPT%, like /etc/profile does in Bash, with the difference that MINGW32/64 environments don't include the basic *MSYS bin* paths and that %MSYSTEM% is not set. Currently it determines MSYS2 root by looking up %MSYS2_ROOT% or trying to find msys2_shell.bat via %PATH% (when it gets a fixed location inside MSYS2, that will of course become much simpler). Usage looks like this:

C:\> msystem msys
<MSYS> C:\> msystem mingw32
<MINGW32> C:\> msystem mingw64
<MINGW64> C:\> msystem /d
C:\>

@Alexpux's first suggestion in IRC was to put it under filesystem/. Is it maybe worth a separate package? Also because I have some further plans like:

  • Extra script dirs dynamically prepended to %PATH%, containing wrapper .bat scripts for most important tools like bash, pacman, makepkg, etc., which directly run in CMD shell, but internally run the actual tools properly through bash --login with %MSYSTEM% set before.
  • Special pacman.bat scripts for MINGW32/64 environments, which implicitly add mingw-w64-i686/x86_64- prefixes to requested package names.
  • ...
  • And last but not least a PowerShell module offering the same features via cmdlets.

But first: what do others think about that stuff?

userzimmermann avatar Sep 11 '15 12:09 userzimmermann

This looks good to me, perhaps put it in a filesystem-cmd package, but it doesn't really matter either way.

I don't like trying to hide the reality of the package names (and thus the difference between them) by implicitly adding anything. This will just lead to increased confusion for little gain.

mingwandroid avatar Sep 11 '15 14:09 mingwandroid

Also, why does it look for msys2_shell.bat in the path; isn't %~dp0 always what you want here?

mingwandroid avatar Sep 11 '15 16:09 mingwandroid

@mingwandroid Because the choco msys2 package neither installs msys2 under the choco package path nor installs msystem.bat into msys2. They are separated. And I wanted the choco package extra tools to be able to work with different msys2 installations depending on env settings...

The msys2-integrated msystem.bat variant will of course work with %~dp0

userzimmermann avatar Sep 11 '15 16:09 userzimmermann

@userzimmermann you should go ahead with the pull request and we can discuss things more on that.

mingwandroid avatar Sep 11 '15 23:09 mingwandroid

@userzimmermann If you don't mind me asking, why do you want to use the CMD shell? I find bash to be pretty nice.

At some point I might make my own pull request to get this script added to MSYS2: https://gist.github.com/DavidEGrayson/2e5923b9c0d8acb3f7a7

I have been using it happily for a while now. It allows me to launch MSYS2 Bash in a normal Windows console if I want, so I still get the nice features of Bash, but native Windows or Java programs that expect a console will automatically behave correctly. I suppose if your script gets added to MSYS2, I could call it from my script or something.

DavidEGrayson avatar Sep 12 '15 00:09 DavidEGrayson

@DavidEGrayson Well, CMD (and PowerShell) are just more Windows ;)

I also like Bash, but only in Unix systems. It just doesn't fit well into a Windows environment (different view on the fileystem, different native path separators, case-sensitive path auto-completion, case-sensitive env var handling, poor integration with other Windows tools/components...)

Bash is of course more powerful than plain CMD, but if you combine CMD with Clink and ConEmu, there are almost no disadvantages left. IMO, Clink is even better than original Readline and its Lua-based auto-completion framework is much cleaner. Just look at my auto-completion scripts for msystem and pacman in #350

userzimmermann avatar Sep 16 '15 07:09 userzimmermann

@mingwandroid Any chance of getting #350 merged? This would be useful for other people who want to use mingw native-Windows binaries without changing their development workflow.

masaeedu avatar May 09 '17 00:05 masaeedu

This looks super useful, it would be great if this could still be merged. Unfortunately the PR #350 was closed as "needinfo".

Note also that msystem.bat is still mentioned to be part of the nonexistent filesystem-cmd package on the MSYS2 Wiki.

triplef avatar Jan 05 '21 09:01 triplef

At least today it the wiki says it is in the msys/filesystem package - and it is, resides directly in the MSYS2 root. I'm adding the info into the new docs with https://github.com/msys2/msys2.github.io/pull/176.

GitMensch avatar Jan 11 '22 14:01 GitMensch