zxsh.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<#
 .Synopsis
  Set title of console Window
 
 .Description
  Set title of console Window
 
 .Parameter $args
  Set title of console Window to $args
 
 .Example
   # Set title of console Window to 'ps7'
   Title ps7
#>


$Script:PrevPwd = $null
$Script:BranchName = $null

Function Set-Title { (Get-Host).UI.RawUI.WindowTitle = $args }

Function Prompt {
    $current_path = (Get-Location).Path
    if ($Script:PrevPwd -ne $current_path)
    {
        $Script:BranchName = $(git branch --show-current)
        $Script:PrevPwd = $current_path
    }    
    "`e[32m$env:USERDOMAIN>$env:USERNAME`e[39m $PWD $(if ($LASTEXITCODE -eq 0) { "`e[36m($Script:BranchName)`e[39m" })`nPS> "
}

New-Alias -Name title -Value Set-Title

# Module member export definitions
Export-ModuleMember -Function Set-Title, Prompt
Export-ModuleMember -Alias title