Windows Bash脚本以一定的大小和位置打开多个git Bash窗口?

Windows Bash脚本以一定的大小和位置打开多个git Bash窗口?,windows,bash,git,git-bash,Windows,Bash,Git,Git Bash,是否可以编写一个bash脚本,在2x3网格中打开六个git窗口,每个窗口为400x400px。见图。这可能吗?我正在运行Windows 10。假设我的显示器是第二个显示器,分辨率为1600 x 1200,具有纵向方向 类似于此,但具有尺寸、x、y位置和六倍: alias bash='/git-bash.exe&>/dev/null 2&>1' 我会使用powershell脚本: Function Set-Window { <# .SYNOPSIS

是否可以编写一个bash脚本,在2x3网格中打开六个git窗口,每个窗口为400x400px。见图。这可能吗?我正在运行Windows 10。假设我的显示器是第二个显示器,分辨率为1600 x 1200,具有纵向方向

类似于此,但具有尺寸、x、y位置和六倍:

alias bash='/git-bash.exe&>/dev/null 2&>1'


我会使用powershell脚本:

Function Set-Window {
    <#
        .SYNOPSIS
            Sets the window size (height,width) and coordinates (x,y) of
            a process window.

        .DESCRIPTION
            Sets the window size (height,width) and coordinates (x,y) of
            a process window.

        .PARAMETER ProcessName
            Name of the process to determine the window characteristics

        .PARAMETER X
            Set the position of the window in pixels from the top.

        .PARAMETER Y
            Set the position of the window in pixels from the left.

        .PARAMETER Width
            Set the width of the window.

        .PARAMETER Height
            Set the height of the window.

        .PARAMETER Passthru
            Display the output object of the window.

        .NOTES
            Name: Set-Window
            Author: Boe Prox
            Version History
                1.0//Boe Prox - 11/24/2015
                    - Initial build

        .OUTPUT
            System.Automation.WindowInfo

        .EXAMPLE
            Get-Process powershell | Set-Window -X 2040 -Y 142 -Passthru

            ProcessName Size     TopLeft  BottomRight
            ----------- ----     -------  -----------
            powershell  1262,642 2040,142 3302,784   

            Description
            -----------
            Set the coordinates on the window for the process PowerShell.exe
        
    #>
    [OutputType('System.Automation.WindowInfo')]
    [cmdletbinding()]
    Param (
        [parameter(ValueFromPipelineByPropertyName=$True)]
        $ProcessName,
        [int]$X,
        [int]$Y,
        [int]$Width,
        [int]$Height,
        [switch]$Passthru
    )
    Begin {
        Try{
            [void][Window]
        } Catch {
        Add-Type @"
              using System;
              using System.Runtime.InteropServices;
              public class Window {
                [DllImport("user32.dll")]
                [return: MarshalAs(UnmanagedType.Bool)]
                public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);

                [DllImport("User32.dll")]
                public extern static bool MoveWindow(IntPtr handle, int x, int y, int width, int height, bool redraw);
              }
              public struct RECT
              {
                public int Left;        // x position of upper-left corner
                public int Top;         // y position of upper-left corner
                public int Right;       // x position of lower-right corner
                public int Bottom;      // y position of lower-right corner
              }
"@
        }
    }
    Process {
        $Rectangle = New-Object RECT
        $Handle = (Get-Process -Name $ProcessName).MainWindowHandle
        $Return = [Window]::GetWindowRect($Handle,[ref]$Rectangle)
        If (-NOT $PSBoundParameters.ContainsKey('Width')) {            
            $Width = $Rectangle.Right - $Rectangle.Left            
        }
        If (-NOT $PSBoundParameters.ContainsKey('Height')) {
            $Height = $Rectangle.Bottom - $Rectangle.Top
        }
        If ($Return) {
            $Return = [Window]::MoveWindow($Handle, $x, $y, $Width, $Height,$True)
        }
        If ($PSBoundParameters.ContainsKey('Passthru')) {
            $Rectangle = New-Object RECT
            $Return = [Window]::GetWindowRect($Handle,[ref]$Rectangle)
            If ($Return) {
                $Height = $Rectangle.Bottom - $Rectangle.Top
                $Width = $Rectangle.Right - $Rectangle.Left
                $Size = New-Object System.Management.Automation.Host.Size -ArgumentList $Width, $Height
                $TopLeft = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Left, $Rectangle.Top
                $BottomRight = New-Object System.Management.Automation.Host.Coordinates -ArgumentList $Rectangle.Right, $Rectangle.Bottom
                If ($Rectangle.Top -lt 0 -AND $Rectangle.LEft -lt 0) {
                    Write-Warning "Window is minimized! Coordinates will not be accurate."
                }
                $Object = [pscustomobject]@{
                    ProcessName = $ProcessName
                    Size = $Size
                    TopLeft = $TopLeft
                    BottomRight = $BottomRight
                }
                $Object.PSTypeNames.insert(0,'System.Automation.WindowInfo')
                $Object            
            }
        }
    }
}
& "$env:ProgramFiles\Git\bin\git-bash.exe"
get-process git-bash | foreach { 
  Set-Window -ProcessName $_ -X 400 -Y 4000
}
函数集窗口{
[OutputType('System.Automation.WindowInfo')]
[cmdletbinding()]
Param(
[参数(ValueFromPipelineByPropertyName=$True)]
$ProcessName,
[int]$X,
[int]$Y,
[int]$Width,
[int]$Height,
[交换机]$Passthru
)
开始{
试一试{
[作废][窗口]
}抓住{
添加类型@”
使用制度;
使用System.Runtime.InteropServices;
公共类窗口{
[DllImport(“user32.dll”)]
[返回:Marshallas(UnmanagedType.Bool)]
公共静态外部bool GetWindowRect(IntPtr hWnd,out RECT lpRect);
[DllImport(“User32.dll”)]
公共外部静态布尔移动窗口(IntPtr句柄、intx、inty、intwidth、intheight、布尔重绘);
}
公共结构矩形
{
public int Left;//左上角的x位置
public int Top;//左上角的y位置
public int Right;//右下角的x位置
public int Bottom;//右下角y位置
}
"@
}
}
过程{
$Rectangle=新对象RECT
$Handle=(获取进程名称$ProcessName).MainWindowHandle
$Return=[Window]::GetWindowRect($Handle,[ref]$Rectangle)
If(-NOT$PSBoundParameters.ContainsKey('Width')){
$Width=$Rectangle.Right-$Rectangle.Left
}
If(-NOT$PSBoundParameters.ContainsKey('Height')){
$Height=$Rectangle.Bottom-$Rectangle.Top
}
如果($返回){
$Return=[Window]::MoveWindow($Handle、$x、$y、$Width、$Height、$True)
}
If($PSBoundParameters.ContainsKey('Passthru')){
$Rectangle=新对象RECT
$Return=[Window]::GetWindowRect($Handle,[ref]$Rectangle)
如果($返回){
$Height=$Rectangle.Bottom-$Rectangle.Top
$Width=$Rectangle.Right-$Rectangle.Left
$Size=新对象System.Management.Automation.Host.Size-参数列表$Width,$Height
$TopLeft=新对象System.Management.Automation.Host.Coordinates-ArgumentList$Rectangle.Left、$Rectangle.Top
$BottomRight=新对象System.Management.Automation.Host.Coordinates-参数列表$Rectangle.Right、$Rectangle.Bottom
如果($Rectangle.Top-lt 0-和$Rectangle.LEft-lt 0){
写入警告“窗口已最小化!坐标将不准确。”
}
$Object=[pscustomobject]@{
ProcessName=$ProcessName
大小=$Size
TopLeft=$TopLeft
BottomRight=$BottomRight
}
$Object.PSTypeNames.insert(0,'System.Automation.WindowInfo')
$Object
}
}
}
}
&“$env:ProgramFiles\Git\bin\Git bash.exe”
获取进程git bash | foreach{
设置窗口-ProcessName$\ux-400-Y 4000
}
设置窗口功能是从

如果有一个执行此操作的
powershell
脚本,您会满意吗?Powershell在windows环境中的性能比bash好得多。@Lenna当然。最终,在我的任务栏中快速启动它会很好,但我可能会将它保存为
.bat
对吗?@Lenna例如,我有一个名为
empty.bat
的文件,它会强制清空我的回收站
PowerShell.exe-NoProfile-Command Clear RecycleBin-Confirm:$false
我需要添加什么才能将其保存为
.bat
文件,以便双击运行?将其保存为.ps1文件,然后双击双击作为.ps1在记事本中打开它。没什么大不了的。我需要调整脚本,因为在PowerShell中运行它只会打开一个git bash实例。