diff --git a/README.md b/README.md index 62cc4bd..9daea39 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,13 @@ available from the [MSYS2][] and [Cygwin][] environments. [msys2]: https://msys2.github.io/ [cygwin]: https://www.cygwin.com/ +There are also wrapper templates for [powershell][go-template-ps1] and +[batch][go-template-cmd] so that the `./go` command can be run directly from +those shells. + +[go-template-ps1]: https://github.com/mbland/go-script-bash/blob/master/go-template.ps1 +[go-template-cmd]: https://github.com/mbland/go-script-bash/blob/master/go-template.cmd + #### Why not use tool X instead? Of course there are many common tools that may be used for managing project @@ -256,6 +263,10 @@ You may rename this file whatever you wish (i.e. it doesn't have to be named `./go`), update its documentation and variables to fit your project, and check it into your project repository. See the `go-template` comments for details. +If windows shell compatibility is desired, then you can also download the +`go-template.ps1` and `go-template.cmd` files. Place them next to your `go` file +with names to match (e.g. `go.ps1` and `go.cmd`). + If you'd prefer to download a copy of the framework and check it into your sources, versioned archives are available from the [go-script-bash Releases page][go-rel]. The archives for the current release are: diff --git a/go-template.cmd b/go-template.cmd new file mode 100644 index 0000000..614bb7e --- /dev/null +++ b/go-template.cmd @@ -0,0 +1 @@ +PowerShell.exe -ExecutionPolicy Bypass -File "%~dpn0.ps1" %* diff --git a/go-template.ps1 b/go-template.ps1 new file mode 100644 index 0000000..2c81226 --- /dev/null +++ b/go-template.ps1 @@ -0,0 +1,29 @@ +function Find-Bash { + @( + , 'bash' # PATH + , "${ENV:ProgramFiles}/Git/bin/bash" # Git + , "${ENV:SystemDrive}/msys64/usr/bin/bash" # MSYS2 + , "${ENV:SystemDrive}/cygwin64/bin/bash" # Cygwin + , "${ENV:LocalppData}/Lxss/bin/bash" # Linux Subsystem + ) | Where-Object { Get-Command $_ -ErrorAction SilentlyContinue } ` + | ForEach-Object { (Get-Command $_).Source } ` + | Select-Object -First 1 +} + +function Execute-Bash($Bash_Path, $Command, $Arguments) { + If ([System.IO.Path]::IsPathRooted($Command)) { + $Command = Resolve-Path -Relative $Command + } + + $Command = $Command -Replace '\\', '/' + + If($Bash_Path -and (Test-Path "${Bash_Path}")) { + &"${Bash_Path}" -c "${Command} ${Arguments}" + } Else { + Throw [System.IO.FileNotFoundException] 'Could not find bash, perhaps it is not installed' + } +} + +$go_path = $MyInvocation.MyCommand.Path -replace '\.ps1$' + +Execute-Bash (Find-Bash) $go_path $args