Skip to content

Instantly share code, notes, and snippets.

@aachyee
Last active June 13, 2021 19:32
Show Gist options
  • Select an option

  • Save aachyee/4cabf3d638b04dff327aa920c4fc3b4b to your computer and use it in GitHub Desktop.

Select an option

Save aachyee/4cabf3d638b04dff327aa920c4fc3b4b to your computer and use it in GitHub Desktop.
msys2/msys2_shell.ps1
# MSYS2 shell wrapper(launcher) implemented with PowerShell.
# It would be nice if we could implement the same functions as 'msys2_shell.cmd'.
# This file must be located at the same directory as 'msys2_shell.cmd'.
# Create the shortcut to "powershell.exe -ExecutionPolicy RemoteSigned -File C:\msys64\msys2_shell.ps1 C:\msys64\user_bash_script.sh" in SendTo directory.
Write-Host "Starting MSYS2 Shell..." -ForegroundColor Cyan
$ErrorActionPreference = 'Inquire' # Inquire(default)/Continue/Stop
Set-StrictMode -Version 3.0
trap {
$ErrorActionPreference = "Continue";
Write-Error $_
# exit 1
Pause
}
# for PS v3 or later
#if( $PSVersionTable.PSVersion.Major -ge 3 ){
# $ScrDir = $PSScriptRoot
#}
# other
#else{
$ScrDir = Split-Path $MyInvocation.MyCommand.Path -Parent
#}
# Add the script directory to path.
# $env:Path += ";$ScrDir"
$Msys2BinDir ="$ScrDir\usr\bin"
$env:Path += ";$Msys2BinDir"
# [Environment]::SetEnvironmentVariable("MSYS2_PATH_TYPE", "inherit", "Machine")
$env:MSYS2_PATH_TYPE = "inherit"
$quotedArgs = $Args | ForEach-Object -Process { '"' + $_ + '"' }
if ($quotedArgs) {
Start-Process -FilePath $Msys2BinDir\bash.exe -Args $quotedArgs
} else {
Start-Process -FilePath $Msys2BinDir\bash.exe
}
# Referrences
# MSYS2-packages/msys2_shell.cmd at master · msys2/MSYS2-packages https://github.com/msys2/MSYS2-packages/blob/master/filesystem/msys2_shell.cmd
# PowerShell Gallery | scripts/Windows/install_msys64.ps1 1.0.174 https://www.powershellgallery.com/packages/AppVeyorBYOC/1.0.174/Content/scripts%5CWindows%5Cinstall_msys64.ps1
# powershell launcher|starter|executer "Write-Host"|"Start-Process" - Google 検索 https://www.google.com/search?q=powershell+launcher%7Cstarter%7Cexecuter+%22Write-Host%22%7C%22Start-Process%22&oq=powershell+launcher%7Cstarter%7Cexecuter+%22Write-Host%22%7C%22Start-Process%22&aqs=chrome..69i57.685j0j9&sourceid=chrome&ie=UTF-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment