6

My current shortcut has the following target: C:\Development\Git\git-bash.exe

How do i get it to execute something more complex such as:

C:\Development\Git\git-bash.exe **ls**

or

C:\Development\Git\git-bash.exe **java -jar myfile.war**

JordanGS
  • 3,966
  • 5
  • 16
  • 21
  • This looks helpful: http://stackoverflow.com/questions/21564275/windows-shortcut-to-run-git-bash-script – Tim Biegeleisen Mar 17 '17 at 04:49
  • @TimBiegeleisen no, i saw those. Those all run from cmd.exe, i don't want to run anything from cmd. – JordanGS Mar 17 '17 at 04:51
  • Just modify the batch file to do what you want; you won't need to open a command prompt when running it, because the OS will do that for you, then close it once the Bash is launched. – Tim Biegeleisen Mar 17 '17 at 04:52
  • @TimBiegeleisen that's not the point tho, there are a lot of ways to do this. I'm not looking for a different method that works. I'm trying to learn how/if i can modify the shortcut to run a command for git-bash. – JordanGS Mar 17 '17 at 04:56

1 Answers1

7

You can modify the shortcut with:

 bash.exe --init-file <(echo "ls; pwd")

If you want git-bash, and in order to avoid git-bash to just open and close a Windows immediately after executing those commands, you would execute (or modify the shortcut):

C:\Development\Git\git-bash.exe -c "ls; $SHELL"

That way, the shell remains in place after executing the first commands you want.


As noted in Baker's comment

In Windows 10/11 the shortcut target is particular about quotes.
This format seems to work:

"C:\Program Files\Git\git-bash.exe" -c "emulator -avd Pixel3a -writable-system; $SHELL"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Just one question, i have an environment variable in my .bashrc which needs to get passed as an argument to my function call but it's not being properly expanded. How would i pass the expanded variable? I tried `${MY_VAR}` to no success. – JordanGS Mar 17 '17 at 07:36
  • @JordanGS Ideally, that environment variable should be defined on the Windows side, not in the bashrc side, as your shortcut is not yet aware of those environment variable definition sourced (read) when the bash is lunching itself. (Assuming here that "passed as an argument to my function call", the "function call" is the `C:\Development\Git\git-bash.exe` call) – VonC Mar 17 '17 at 07:42
  • @JordanGS If "my function call" refers to some function within the bash session, then make sure the `.basrc` defines `MY_VAR` with `export MY_VAR=xxx`. Then `${MY_VAR}` would work. – VonC Mar 17 '17 at 07:43
  • In Windows 10/11 the shortcut target is particular about quotes. This format seems to work: `"C:\Program Files\Git\git-bash.exe" -c "emulator -avd Pixel3a -writable-system; $SHELL"` – Baker Jan 12 '22 at 16:07
  • @Baker Thank you for the feedback. I have edited the answer to include your comment for more visibility. – VonC Jan 12 '22 at 19:03