-
-
Save anaman/e9ff3b7d1947a9d5c24d469030af14ba to your computer and use it in GitHub Desktop.
Windows Terminal Split Pane Powershell Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PaneCommand { | |
[string]$Command | |
PaneCommand() { | |
$this.Command = ""; | |
} | |
PaneCommand([string]$command) { | |
$this.Command = $command | |
} | |
[string]GetCommand() { | |
return $this.Command | |
} | |
[string]ToString() { | |
return $this.GetCommand(); | |
} | |
} | |
class Pane : PaneCommand { | |
[string]$Command | |
[string]$Orientation | |
[decimal]$Size; | |
Pane([string]$command, [string]$orientation) : base($command) { | |
$this.Orientation = $orientation; | |
$this.size = 0.5; | |
} | |
Pane([string]$command, [string]$orientation, [decimal]$size) : base($command) { | |
$this.Orientation = $orientation; | |
$this.size = $size; | |
} | |
[string]GetCommand() { | |
return 'split-pane --size {0} {1} -p "Windows Powershell" -c powershell {2}' -f $this.Size, $this.Orientation, $this.Command | |
} | |
} | |
class InitialPane : PaneCommand { | |
InitialPane([string]$command) : base($command) { | |
} | |
[string]GetCommand() { | |
return '--maximized -p "Windows Powershell" {0}' -f $this.Command | |
} | |
} | |
class TargetPane : PaneCommand { | |
[int]$index; | |
TargetPane([int]$index) { | |
$this.index = $index; | |
} | |
[string]GetCommand() { | |
return "focus-pane --target {0}" -f $this.index; | |
} | |
} | |
class MoveFocus : PaneCommand { | |
[string]$direction; | |
MoveFocus([string]$direction) { | |
$this.direction = $direction; | |
} | |
[string]GetCommand() { | |
return 'move-focus --target {0}' -f $this.direction; | |
} | |
} | |
class PaneManager { | |
[InitialPane]$InitialPane; | |
[System.Collections.Generic.List[PaneCommand]]$PaneCommands; | |
PaneManager() { | |
$this.InitialPane = [InitialPane]::new("") | |
$this.PaneCommands = New-Object "System.Collections.Generic.List[PaneCommand]" | |
} | |
[void]SetInitialPane($command) { | |
$this.InitialPane = [InitialPane]::new($command) | |
} | |
[void]AddCommand([PaneCommand]$command) { | |
$this.PaneCommands.Add($command) | |
} | |
[void]AddPane([string]$command, [string]$orientation) { | |
$newPane = [Pane]::new($command, $orientation); | |
$this.AddCommand($newPane); | |
} | |
[void]MoveAndAddPane([string]$splitTarget, [string]$command, [string]$orientation) { | |
$this.MoveFocus($splitTarget); | |
$newPane = [Pane]::new($command, $orientation); | |
$this.AddCommand($newPane); | |
} | |
[void]AddPane([string]$command, [string]$orientation, [decimal]$size) { | |
$newPane = [Pane]::new($command, $orientation, $size) | |
$this.AddCommand($newPane); | |
} | |
[void]MoveAndAddPane( [string]$splitTarget, [string]$command, [string]$orientation, [decimal]$size) { | |
$this.MoveFocus($splitTarget); | |
$newPane = [Pane]::new($command, $orientation, $size) | |
$this.AddCommand($newPane); | |
} | |
[void]TargetPane([int]$index) { | |
$targetCommand = [TargetPane]::new($index) | |
$this.AddCommand($targetCommand) | |
} | |
[void]MoveFocus([string]$direction) { | |
$targetCommand = [MoveFocus]::new($direction) | |
$this.AddCommand($targetCommand) | |
} | |
[string]ToString() { | |
return "{0};{1}" -f $this.InitialPane, ($this.PaneCommands -join ";") | |
} | |
} | |
$paneManager = New-Object -TypeName PaneManager; | |
$paneManager.AddPane("connect_office", "-V", .70); | |
$paneManager.AddPane("connect_rbp01", "-H", .70); | |
$paneManager.AddPane("connect_rbp02", "-V", .5); | |
$paneManager.MoveAndAddPane("left", "connect_rbp03", "-H", .66); | |
$paneManager.MoveAndAddPane("right", "connect_rbp04", "-H", .66); | |
$paneManager.MoveAndAddPane("left", "connect_rbp05", "-H", .5); | |
$paneManager.MoveAndAddPane("right", "connect_rbp06", "-H", .5); | |
start wt $paneManager |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment