Windows shortcut to run a Git Bash script

前端 未结 4 1742
轮回少年
轮回少年 2020-12-01 05:21

Assuming I have a test.sh script that runs a server and Git Bash installed, how do I create a Windows shortcut that I can double click to run tesh.sh in Git Bash in the fore

4条回答
  •  渐次进展
    2020-12-01 05:52

    Best solution in my opinion:

    • Invokes the right shell
    • No unnecessary windows
    • Invokes a bash script afterwards
    • Window will stay open after the script exits

    Do the following:

    1. Create a shortcut to mintty.exe on your desktop, for example. It is found under %installation dir%/Git/usr/bin/mintty.exe

    2. Edit properties of the shortcut and change the target (keep the path):

    "C:\Program Files\Git\usr\bin\mintty.exe" -h always /bin/bash -l -e 'D:\folder\script.sh'


    Explanation of the parameters:

    -h always keeps the window open when the script finished, so the window won’t disappear while you are still reading the output (remove if you don’t need to read the output and want the window to close automatically).

    -l makes this shell act as if it had been directly invoked by login.

    -e exits immediately if a pipeline returns a non-zero status (more info).

提交回复
热议问题