diff --git a/README.md b/README.md index 3bd3eab..2e0507a 100644 --- a/README.md +++ b/README.md @@ -29,5 +29,6 @@ A feature-barren DOS clone of `ls` that hides Windows hidden files. Relies on - `dos.sh`: Simple wrapper for executing Windows commands directly. - `elevate.sh`: Elevate WSL (`-l`) or Windows (`-w`) commands from WSL. - `explorer.sh`: Launch explorer from WSL. +- `pwsh.sh`: Launch PowerShell Core. - `terminal.sh`: Launch Windows Terminal. diff --git a/scripts/justfile b/scripts/justfile index 805c93b..5f687ea 100644 --- a/scripts/justfile +++ b/scripts/justfile @@ -5,5 +5,6 @@ install DIR="~/.bin": cp dos.sh {{DIR}}/dos cp elevate.sh {{DIR}}/elevate cp explorer.sh {{DIR}}/explorer + cp pwsh.sh {{DIR}}/pwsh cp terminal.sh {{DIR}}/terminal diff --git a/scripts/pwsh.sh b/scripts/pwsh.sh new file mode 100755 index 0000000..2420ac0 --- /dev/null +++ b/scripts/pwsh.sh @@ -0,0 +1,27 @@ +#!/usr/bin/bash + +# try to use system-wide version first. +# this usually fails, but it's worth a shot. +if [[ -r '/mnt/c/Program Files/WindowsApps/' ]]; then + cd '/mnt/c/Program Files/WindowsApps/' + PWSH="`pwd`/`find Microsoft.PowerShell_* -name 'pwsh.exe'`" + cd - > /dev/null + if ! [ -x "$PWSH" ]; then + unset PWSH + fi +fi + +# fall back to user installation +if [ -z ${PWSH+x} ]; then + # absolutely monstrous string hackery + # get %USERPROFILE% using cmd and convert that path + USERPROFILE=`/mnt/c/Windows/System32/cmd.exe '/C' 'echo %USERPROFILE%' 2> /dev/null` + USERPROFILE=${USERPROFILE//\\//} # replace '\' separators with '/' + USERPROFILE=/mnt/c/${USERPROFILE#C:/} # replace 'C:/' with '/mnt/c/' + USERPROFILE=${USERPROFILE%$'\r'} # strip carriage return + PWSH="$USERPROFILE/AppData/Local/Microsoft/WindowsApps/pwsh.exe" +fi + +# run target +"$PWSH" $@ +