79715847

Date: 2025-07-26 16:52:00
Score: 0.5
Natty:
Report link

With some other answers on stackoverflow and with some help from Gemini AI, here's what works.

The python script:

def _start_msys2_terminal(self, next_dir):
    win_dir = next_dir.replace('~', os.path.expanduser('~'))
    win_dir = win_dir.replace('/', '\\')
    os.system(f'cd /d "{win_dir}" & mintty.exe -s 80,42 bash --login -i')

This opens a new MSYS2 shell, with the cols/rows (80,42), runs .bash_profile and .bashrc as expected, and cd's into the given dirctory

So I end up with two terminals. The original one where I ran the function above and a new one with a bash shell at the new directory. This is what I wanted.

e.g. if I run _start_msys2_terminal('~/projects/web/xplat-utils-rb-ut'), the new terminal shows:

in /c/Users/micro/.bash_profile HOME=/c/Users/micro
in .bashrc
HOME is /c/Users/micro, OSTYPE is cygwin
micro@mypc:~/projects/web/xplat-utils-rb-ut$

Please note, as far as I can tell, the script C:/msys64/msys2_shell.cmd does not have the capability of changing directories and setting mintty geometry. Also note I do not know DOS scripts, commands, etc. very well so it may actually be possible.

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: JohnA