#!/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" $@