Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add windows templates for powershell and batch #232

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions go-template.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PowerShell.exe -ExecutionPolicy Bypass -File "%~dpn0.ps1" %*
29 changes: 29 additions & 0 deletions go-template.ps1
Original file line number Diff line number Diff line change
@@ -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