scripts: created userprofile script

This commit is contained in:
Valerie Wolfe 2024-07-08 13:25:59 -04:00
parent 2798682a1d
commit 18389ca9b8
4 changed files with 13 additions and 7 deletions

View file

@ -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%`).

View file

@ -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

View file

@ -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

10
scripts/userprofile.sh Executable file
View file

@ -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