-
Notifications
You must be signed in to change notification settings - Fork 0
/
powershell-wrapper
executable file
·55 lines (53 loc) · 1.49 KB
/
powershell-wrapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
powerExe=""
if [ ! -e "${1}" ]; then
echo could not find script "${1}" to execute
exit 1
fi
sysroot=$(cmd.exe /c "echo %SYSTEMROOT%"|grep -o '^.'|tr '[:upper:]' '[:lower:]')
[ -z "${sysroot}" ] && sysroot=c
{
if ( command -v powershell.exe )
then
powerExe="$(which powershell.exe)"
elif ( command -v "/mnt/${sysroot}/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" )
then
powerExe="/mnt/${sysroot}/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
elif ( command -v "/mnt/${sysroot}/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" )
then
powerExe="/mnt/${sysroot}/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
elif ( command -v pwsh.exe )
then
powerExe="$(which pwsh.exe)"
elif ( command -v "/mnt/${sysroot}/Program Files/PowerShell/7/pwsh.exe" )
then
powerExe="/mnt/${sysroot}/Program Files/PowerShell/7/pwsh.exe"
else
drives=$(grep -i 9p /proc/mounts|grep -oi " /mnt/. ")
for drive in ${drives}
do
if ( command -v "/mnt/${drive}/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" )
then
powerExe="/mnt/${drive}/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
fi
done
fi
} > /dev/null
if [ -z "${powerExe}" ]
then
echo powershell executable could not be found, exiting.
exit 1
fi
args=( "$@" )
newargs=()
for var in "${args[@]}"
do
if [ -e "${var}" ]
then
nextitem=$(wslpath -w "$(realpath "${var}")")
else
nextitem="${var}"
fi
newargs+=("${nextitem}")
done
"${powerExe}" -file "${newargs[0]}" "${newargs[@]:1}"