windowsbatch-filemsys2

How can I get a batch script to keep an Msys2 terminal open?


I'm trying to write a batch file that will automate opening all of the MinGW64 terminal windows I plan to open and cd into an appropriate directory. My work PC uses Windows 11.

Right now, I'm using this command to get something running:

start "" C:\msys64\mingw64.exe "cd repos"

However, while this does cause a mingw64 terminal to appear and what I presume cd into the repos folder, that terminal immediately closes instead of staying active. If I append a call to vim after the cd command, it stays active as expected but closes when I quit vim.

I've found the following 2 questions that appear to be related to what I'm trying, but the presented solutions don't work for me:

  1. Uses the start command
  2. Uses the cmd script provided by msys2

Both of these still have the same result of immediately closing the window.

How can I make a batch script that creates a MinGW64 terminal window and keeps it active after it's done executing any provided commands?

EDIT: Again, I'm not asking how to run a command in the MinGW64 terminal from the batch script. I'm asking how to keep that terminal ACTIVE when it would otherwise wait for user input? I'm trying to stop the process from killing the terminal after the supplied command(s) is(are) finished executing and instead wait for me to kill the terminal manually. As if it were at the state of a blinking cursor waiting for user input.


Solution

  • This batch file works for me:

    start /D C:\ "" C:\msys64\mingw64.exe bash -c "nano somefile; bash"
    

    I tested it by saving it in a file named "test.bat" and then double-clicking on it in Windows Explorer. When I terminate nano, it starts a bash shell.