Skip to content

Instantly share code, notes, and snippets.

@Trucido
Last active February 2, 2019 13:15
Show Gist options
  • Save Trucido/f324a644abbe1c27c21a290fc06d7a29 to your computer and use it in GitHub Desktop.
Save Trucido/f324a644abbe1c27c21a290fc06d7a29 to your computer and use it in GitHub Desktop.
# Invoke MSYS bash directly without msys2_shell.cmd
function mbash {
param(
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$RemainingArgs
)
$msysArgs = @(
'MSYSTEM=MSYS' , 'MSYS2_PATH_TYPE=' ,
'MSYSCON=' , 'MSYS=winsymlinks:nativestrict',
'LOGINSHELL=bash', '/usr/bin/bash' ,
'--login', '-i'
)
if ($RemainingArgs) { $msysArgs += '-c',$RemainingArgs }
if ($null -ne (
$msysPath = Get-ChildItem "${env:SystemDrive}\" -Recurse `
-Depth 2 -Filter "msys2_shell.cmd" -EA 0 |
foreach { Split-Path $_.FullName -Parent } )
) {} else { throw(New-Object([IO.DirectoryNotFoundException]'')) }
pushd $msysPath -ErrorAction:Stop # Push-Location
.\usr\bin\env.exe @msysArgs
popd # Pop-Location
}
# Invoke MINGW64 bash directly without msys2_shell.cmd
function mgwbash {
param(
[Parameter(ValueFromRemainingArguments=$true)]
[string[]]$RemainingArgs
)
$msysArgs = @(
'MSYSTEM=MINGW64', 'MSYS2_PATH_TYPE=inherit' ,
'MSYSCON=' , 'MSYS=winsymlinks:nativestrict',
'LOGINSHELL=bash', '/usr/bin/bash' ,
'--login', '-i'
)
if ($null -ne (
$msysPath = Get-ChildItem "${env:SystemDrive}\" -Recurse `
-Depth 2 -Filter "msys2_shell.cmd" -EA 0 |
foreach { Split-Path $_.FullName -Parent } )
) {} else { throw(New-Object([IO.DirectoryNotFoundException]'')) }
if ($RemainingArgs) { $msysArgs += '-c',$RemainingArgs }
pushd $msysPath -ErrorAction:Stop # Push-Location
.\usr\bin\env.exe @msysArgs
popd # Pop-Location
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment