2

I'm writing git commands through a Python script (on Windows) When I double click on myScript.py, commands are launched in the Windows Command Prompt. I would like to execute them in Git Bash.

Any idea how to do that without opening Git Bash and write python myScript.py?

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Benjamin
  • 84
  • 1
  • 2
  • 6

2 Answers2

2

You can create a batch file (.bat) with the following content:

"C:\Program Files\Git\git-bash.exe" -c "python myScript.py"

Yu can also make this available for all .py file by editing your regedit as explained here: Adding a context menu item in Windows for a specific file extension with the following command:

"C:\Program Files\Git\git-bash.exe" -c "python \"%1\""
scholi
  • 314
  • 2
  • 10
0

in the top of your python file add #!/usr/bin/python then you can rename mv myScript.py myScript and run chmod 755 myScript. This will make it so you can run the file with ./myScript look into adding the file directory to your path or linking it to the path if you want to be able to run it from anywhere.

GleasonK
  • 1,032
  • 8
  • 17