From 86173268f90162a3ba469699b71941d1bb8c484b Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Sun, 22 Dec 2019 14:03:31 -0500 Subject: [PATCH 1/2] Don't fail when powershell.exe is missing On some platforms, `uname -a` contains `Microsoft` but `powershell.exe` is not in `$PATH`, so `if powershell.exe ... 2>/dev/null` still displays an error: ``` if powershell.exe -command "Import-Module -Name BurntToast" 2>/dev/null; echo true; end powershell.exe: command not found fish: if powershell.exe -command "Import-Module -Name BurntToast" 2>/dev/null; echo true; end ^ ``` Add a check to `command -v powershell.exe` to avoid the error message. --- conf.d/done.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf.d/done.fish b/conf.d/done.fish index 64a1f8b..d67430c 100644 --- a/conf.d/done.fish +++ b/conf.d/done.fish @@ -155,7 +155,7 @@ if test -z "$SSH_CLIENT" # not over ssh end else if uname -a | string match --quiet --regex Microsoft - if powershell.exe -command "Import-Module -Name BurntToast" 2>/dev/null + if command -v powershell.exe; and powershell.exe -command "Import-Module -Name BurntToast" 2>/dev/null if test "$__done_notify_sound" -eq 1 set soundopt "-Sound Default" end From 08261a3186f7c821c09f3f29cd3a017447a7d009 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Mon, 23 Dec 2019 14:56:33 -0500 Subject: [PATCH 2/2] Be better at finding PowerShell to support WSL - On WSL, `uname -a` contains `Microsoft` but `powershell.exe` is often not in `$PATH`; therefore, we use `wslpath` and `wslvar` to make a better guess as to `powershell.exe`'s location if we can't find it in `$PATH`. - Fall back to the bell sound (`echo -e "\a"`) if we can't find PowerShell or PowerShell can't import the `BurntToast` module. --- conf.d/done.fish | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/conf.d/done.fish b/conf.d/done.fish index d67430c..09d2f5f 100644 --- a/conf.d/done.fish +++ b/conf.d/done.fish @@ -154,13 +154,17 @@ if test -z "$SSH_CLIENT" # not over ssh echo -e "\a" # bell sound end - else if uname -a | string match --quiet --regex Microsoft - if command -v powershell.exe; and powershell.exe -command "Import-Module -Name BurntToast" 2>/dev/null - if test "$__done_notify_sound" -eq 1 - set soundopt "-Sound Default" - end - powershell.exe -command New-BurntToastNotification -Text \""$title"\",\""$message"\" $soundopt + else if uname -a | string match --quiet --regex Microsoft; \ + and set -l powershell_exe (command -v "powershell.exe"); \ + or set -l powershell_exe \ + (wslpath (wslvar windir)/System32/WindowsPowerShell/v1.0/powershell.exe); \ + and test -x "$powershell_exe"; \ + and "$powershell_exe" -command "Import-Module -Name BurntToast" 2>/dev/null + + if test "$__done_notify_sound" -eq 1 + set soundopt "-Sound Default" end + command "$powershell_exe" -command New-BurntToastNotification -Text \""$title"\",\""$message"\" $soundopt else # anything else echo -e "\a" # bell sound