How can I play a sound when my Git for Windows Bash command prompt is ready?

I use the shell Git for Windows Bash on Windows 10 and I want to play a sound whenever my command prompt is ready. This acoustic feedback should help me to get (back) to my command line when my Terminal window is fully initialized or a command finished executing.

This is my current .bash_profile line:

export PROMPT_COMMAND='history -a && powershell -c "(New-Object Media.SoundPlayer C:/Windows/Media/chimes.wav).PlaySync();"'
  • The history command is not relevant and comes from here.
  • The powershell command comes from here. It does basically work, but it's sync and delays my command prompt loading.

How can I make this async? I tried nohup and & but those did not work here. Docs mention method Play, but this doesn't create a sound at all.


Solution 1:

To run something asynchronously (in the background) you place & at the end (where ; could otherwise be). powershell -c … & basically should work.

In an interactive Bash job control is enabled by default and powershell -c … & triggers a message from the shell when done (even if run from PROMPT_COMMAND). Run the command in an explicit subshell to circumvent. It will be like this:

(powershell -c … &)

The subshell itself will run synchronously, so the current shell won't treat it as a job. The command inside will run asynchronously, but it won't become a job of the current shell.

This should work:

export PROMPT_COMMAND='history -a && (powershell -c "(New-Object Media.SoundPlayer C:/Windows/Media/chimes.wav).PlaySync();" &)'