diff --git a/README.md b/README.md index 4b5f887..c0f2cbb 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,5 @@ A feature-barren DOS clone of `ls` that hides Windows hidden files. Relies on - `explorer.sh`: Launch explorer from WSL. - `pwsh.sh`: Launch PowerShell Core. - `terminal.sh`: Launch Windows Terminal. +- `userprofile.sh`: Get the Windows user profile directory (`%USERPROFILE%`). diff --git a/scripts/justfile b/scripts/justfile index 5f687ea..a6210f0 100644 --- a/scripts/justfile +++ b/scripts/justfile @@ -7,4 +7,5 @@ install DIR="~/.bin": cp explorer.sh {{DIR}}/explorer cp pwsh.sh {{DIR}}/pwsh cp terminal.sh {{DIR}}/terminal + cp userprofile.sh {{DIR}}/userprofile diff --git a/scripts/pwsh.sh b/scripts/pwsh.sh index 2420ac0..6691297 100755 --- a/scripts/pwsh.sh +++ b/scripts/pwsh.sh @@ -13,13 +13,7 @@ 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" + PWSH="`userprofile`/AppData/Local/Microsoft/WindowsApps/pwsh.exe" fi # run target diff --git a/scripts/userprofile.sh b/scripts/userprofile.sh new file mode 100755 index 0000000..ba8902c --- /dev/null +++ b/scripts/userprofile.sh @@ -0,0 +1,10 @@ +#!/usr/bin/bash + +# 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 +echo $USERPROFILE +