Skip to content

Commit

Permalink
✨ added wrapper scripts for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Apr 26, 2024
1 parent 198cfa4 commit c6f3522
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 1 deletion.
57 changes: 57 additions & 0 deletions valet.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@REM -----------------------------------------------------------------------------
@REM Valet Startup Script for windows
@REM Allows to run valet from the windows command prompt.
@REM
@REM Environment Variable Prerequisites
@REM VALET_BIN_BASH Must point to bash executable (defaults to C:\Program Files\Git\bin\bash.exe).
@REM -----------------------------------------------------------------------------
@REM Begin all REM lines with '@' for safety
@echo off

@setlocal

set ERROR_CODE=0

@REM Try to find the path to bash.exe or fail
if not "%VALET_BIN_BASH%"=="" goto GotBinBash
set "VALET_BIN_BASH=C:\Program Files\Git\bin\bash.exe"
if exist "%VALET_BIN_BASH%" goto GotBinBash
for %%i in (bash.exe) do set "VALET_BIN_BASH=%%~$PATH:i"
if exist "%VALET_BIN_BASH%" goto chkMHome
echo The VALET_BIN_BASH environment variable is not defined correctly, >&2
echo it should point to the bash.exe executable that can be found in a Git bash installation. >&2
echo This environment variable is needed to run this program. >&2
echo Exiting now... >&2
goto error

:GotBinBash

@REM Try to find the path to valet
if not "%VALET_HOME%"=="" goto GotValetHome
set "VALET_HOME=%~dp0"
if exist "%VALET_HOME%\valet" goto GotValetHome

echo The valet script is not present in the same directory of this script. >&2
echo Please override the path to your valet installation directory. >&2
echo by defining the VALET_HOME environment variable. >&2
goto error

:GotValetHome
@REM Convert windows path to unix path
set VALET_HOME=%VALET_HOME:\=/%
set VALET_HOME=%VALET_HOME::=%

@REM trim the trailing slash
if "%VALET_HOME:~-1%"=="\" set VALET_HOME=%VALET_HOME:~0,-1%

bash.exe -c "/%VALET_HOME%/valet %*"

if ERRORLEVEL 1 goto error
goto end

:error
set ERROR_CODE=1

:end
@endlocal & set ERROR_CODE=%ERROR_CODE%

2 changes: 1 addition & 1 deletion valet.d/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.0
0.10.4
66 changes: 66 additions & 0 deletions valet.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<#
.SYNOPSIS
Allows to run valet from powershell.
.DESCRIPTION
Call windows Git bash and run valet command.
.EXAMPLE
./valet.ps1
./valet.ps1 -shouldExit 1
#>
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 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 { $_ + " " }

# echo the command that will be run
Write-Host "$bashPath -c $valetHome/valet $quotedArgs"

# run bash with the valet script, throw an error if the exit code is not 0
& $bashPath -c "$valetHome/valet $quotedArgs"
}

Main $args

0 comments on commit c6f3522

Please sign in to comment.