-
Notifications
You must be signed in to change notification settings - Fork 0
/
valet.ps1
67 lines (51 loc) · 2.11 KB
/
valet.ps1
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
56
57
58
59
60
61
62
63
64
65
66
67
<#
.SYNOPSIS
Allows to run valet from powershell.
.DESCRIPTION
Call windows Git bash and run valet command.
.EXAMPLE
./valet.ps1
#>
function Main {
# Find the path to bash.exe
# get it from the environment variable
[string] $bashPath = $env:VALET_BIN_BASH
# check if the path exists, otherwise try a hard coded value
if (-Not (Test-Path $bashPath)) {
$bashPath = "C:\Program Files\Git\bin\bash.exe"
}
# check if the path exists, otherwise try a hard coded value
if (-Not (Test-Path $bashPath)) {
$bashPath = "$env:LOCALAPPDATA\Programs\Git\bin\bash.exe"
}
# check if the path exists, otherwise try to find bash.exe in the path
if (-Not (Test-Path $bashPath)) {
$bashPath = Get-Command bash.exe | Select-Object -ExpandProperty Source
}
# Check if the path exists, otherwise throw an error
if (-Not (Test-Path $bashPath)) {
throw "The VALET_BIN_BASH environment variable is not defined correctly, it should point to the bash.exe executable that can be found in a Git bash installation. This environment variable is needed to run this program."
}
# Find the path to Valet home
# get it from the environment variable
[string] $valetHome = $env:VALET_HOME
# check if the path exists, otherwise try the current directory + valet
if (-Not (Test-Path $valetHome)) {
$valetHome = "$PSScriptRoot"
}
# check if the path exists, otherwise throw an error
if (-Not (Test-Path $valetHome)) {
throw "The valet script is not present in the same directory of this script. Please override the path to your valet installation directory by defining the VALET_HOME environment variable."
}
# convert the valet home path to a bash path
$valetHome = $valetHome.Replace("\", "/")
$valetHome = $valetHome.Replace(":", "")
$valetHome = "/$valetHome"
# trim trailing / if present
$valetHome = $valetHome.TrimEnd("/")
# convert arguments to a string where each argument is separated by a space
[string] $quotedArgs = $args | ForEach-Object { $_ + " " }
# run bash with the valet script, throw an error if the exit code is not 0
& $bashPath -c "$valetHome/valet $quotedArgs"
}
Main $args