Benjamin
Benjamin

Reputation: 84

Launch Python script in Git Bash

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?

Upvotes: 2

Views: 35793

Answers (2)

scholi
scholi

Reputation: 314

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\""

Upvotes: 2

GleasonK
GleasonK

Reputation: 1022

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.

Upvotes: 0

Related Questions