Commit 25cabe55 authored by Dustin L. Howett's avatar Dustin L. Howett

Update with Libra.

parent 4ce282a5
PromptEd @ 09ec07bb
Subproject commit 09ec07bb121e0a90be2082aa30137978a06333f1
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[String[]]
$Disks
)
$shlApp = New-Object -ComObject Shell.Application
$thisPc = $shlApp.Namespace(17)
$nEjected = 0
foreach($disk in $Disks) {
$shlDisk = $thisPc.ParseName($disk)
if($shlDisk) {
$ejectVerb = $shlDisk.Verbs() | Where { $_.Name -eq "E&ject" }
if($ejectVerb) {
$ejectVerb.DoIt()
$nEjected++
} else {
Write-Host -ForegroundColor Red "$disk is not removable."
}
} else {
Write-Host -ForegroundColor Red "$disk is not mounted."
}
}
Write-Host "$nEjected volume$(@{$true='s';$false=''}[$nEjected -ne 1]) ejected."
Write-Host ""
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$Files
)
& clang-format -i ($Files -Join " ")
Param (
[String[]]
$InputStrings
)
If($null -eq $InputStrings) {
$InputStrings = @($input)
}
$Script:n = 0
$InputStrings | Select -Property (
@{Name="S";Expression={$_}},
@{Name="U";Expression={$_.ToUpper()}},
@{Name="I";Expression={$Script:n++; $Script:n}}
) | Sort -Property U -Unique | Sort -Property I | Select -ExpandProperty S
function prompt {
$Host.UI.RawUI.WindowTitle = "PowerShell v" + (get-host).Version.Major + "." + (get-host).Version.Minor + " (" + $pwd.Provider.Name + ") " + $pwd.Path
$Env:PATH += ";$(Split-Path $Profile)\Scripts"
Write-Host "(" -nonewline -foregroundcolor Blue
If($null -ne $Global:DevEnv -and $Global:DevEnv.Name) {
Write-Host $Global:DevEnv.Name -nonewline -foregroundcolor Green
Write-Host "\" -nonewline -foregroundcolor Blue
}
Write-Host $env:COMPUTERNAME.ToLower() -nonewline -foregroundcolor White
Write-Host ") " -nonewline -foregroundcolor Blue
# PSReadline profile
Set-PSReadlineOption -EditMode Emacs
Set-PSReadlineKeyHandler "Ctrl+Delete" KillWord
Set-PSReadlineKeyHandler "Ctrl+Backspace" BackwardKillWord
Set-PSReadlineKeyHandler "Ctrl+LeftArrow" BackwardWord
Set-PSReadlineKeyHandler "Ctrl+RightArrow" NextWord
Import-Module PromptEd -EA Ignore
# Fallback: If PromptEd is not installed, render a legacy prompt.
If($null -eq (Get-Module PromptEd)) {
Function Prompt {
$Host.UI.RawUI.WindowTitle = "PowerShell v" + (get-host).Version.Major + "." + (get-host).Version.Minor + " (" + $pwd.Provider.Name + ") " + $pwd.Path
Write-Host "(" -nonewline -foregroundcolor Blue
If($null -ne $Global:DevEnv -and $Global:DevEnv.Name) {
Write-Host $Global:DevEnv.Name -nonewline -foregroundcolor Green
Write-Host "\" -nonewline -foregroundcolor Blue
}
Write-Host $env:COMPUTERNAME.ToLower() -nonewline -foregroundcolor White
Write-Host ") " -nonewline -foregroundcolor Blue
# Show providername if you are outside FileSystem
if ($pwd.Provider.Name -ne "FileSystem") {
Write-Host $pwd.Provider.Name.ToLower() -nonewline -foregroundcolor DarkMagenta
if ($pwd.ProviderPath[0] -ne "\") {
Write-Host ":\" -nonewline -foregroundcolor DarkMagenta
} else {
Write-Host ":" -nonewline -foregroundcolor DarkMagenta
if ($pwd.Provider.Name -ne "FileSystem") {
Write-Host $pwd.Provider.Name.ToLower() -nonewline -foregroundcolor DarkMagenta
if ($pwd.ProviderPath[0] -ne "\") {
Write-Host ":\" -nonewline -foregroundcolor DarkMagenta
} else {
Write-Host ":" -nonewline -foregroundcolor DarkMagenta
}
}
}
# Split path and write \ in a gray
#$pwd.Path.Split("\") | foreach {
# Write-Host $_ -nonewline -foregroundcolor Yellow
# Write-Host "\" -nonewline -foregroundcolor Gray
#}
Write-Host $pwd.ProviderPath.Replace($env:USERPROFILE, "~") -nonewline -foregroundcolor Magenta
Write-Host $pwd.ProviderPath.Replace($env:USERPROFILE, "~") -nonewline -foregroundcolor Magenta
# Admin ?
if((
New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host " #" -nonewline -foregroundcolor Green
} else {
Write-Host " %" -nonewline -foregroundcolor Green
if((
New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host " #" -nonewline -foregroundcolor Green
} else {
Write-Host " %" -nonewline -foregroundcolor Green
}
return " "
}
return " "
}
Function Set-Prompt([string]$prompt) {
}
} Else {
Function pe_Hostname {
Write-Host "(" -NoNewLine -ForegroundColor (Get-PromptColor Brackets)
Write-Host $env:COMPUTERNAME.ToLower() -NoNewLine -ForegroundColor (Get-PromptColor Hostname)
Write-Host ")" -NoNewLine -ForegroundColor (Get-PromptColor Brackets)
}
function Eject-Disk {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
[String[]]
$Disks
)
$shlApp = New-Object -ComObject Shell.Application
$thisPc = $shlApp.Namespace(17)
$nEjected = 0
foreach($disk in $Disks) {
$shlDisk = $thisPc.ParseName($disk)
if($shlDisk) {
$ejectVerb = $shlDisk.Verbs() | Where { $_.Name -eq "E&ject" }
if($ejectVerb) {
$ejectVerb.DoIt()
$nEjected++
} else {
Write-Host -ForegroundColor Red "$disk is not removable."
}
} else {
Write-Host -ForegroundColor Red "$disk is not mounted."
}
}
Write-Host "$nEjected volume$(@{$true='s';$false=''}[$nEjected -ne 1]) ejected."
Write-Host ""
Function pe_DevEnvHostname {
Write-Host "(" -NoNewLine -ForegroundColor (Get-PromptColor Brackets)
If($null -ne $Global:DevEnv -and $Global:DevEnv.Name) {
Write-Host $Global:DevEnv.Name -NoNewLine -ForegroundColor (Get-PromptColor DevEnv)
Write-Host "\" -NoNewLine -ForegroundColor (Get-PromptColor Brackets)
}
Write-Host $env:COMPUTERNAME.ToLower() -NoNewLine -ForegroundColor (Get-PromptColor Hostname)
Write-Host ")" -NoNewLine -ForegroundColor (Get-PromptColor Brackets)
}
Function pe_Provider {
if ($PWD.Provider.Name -ne "FileSystem") {
Write-Host $PWD.Provider.Name.ToLower() -NoNewLine -ForegroundColor (Get-PromptColor Provider)
if ($PWD.ProviderPath[0] -ne "\") {
Write-Host ":\" -NoNewLine -ForegroundColor (Get-PromptColor Provider)
} else {
Write-Host ":" -NoNewLine -ForegroundColor (Get-PromptColor Provider)
}
}
}
Function pe_ShortHomePath {
Write-Host $PWD.ProviderPath.Replace($HOME, "~") -NoNewLine -ForegroundColor (Get-PromptColor Path)
}
Function pe_Sigil {
if((
New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "#" -NoNewLine -ForegroundColor (Get-PromptColor Sigil)
} else {
Write-Host "%" -NoNewLine -ForegroundColor (Get-PromptColor Sigil)
}
}
Function pe_LastCommandRunTime {
If ($global:_LastCommandTimeSpan -And ($global:_LastCommandTimeSpan.TotalSeconds) -Ge 10) {
# Format buffer: Total Minutes, Seconds, Milliseconds
# We could use total seconds in the second position, but it's only ever used as a primary
# unit if it numbers less than 60.
$fmtBuff = ([int]$global:_LastCommandTimeSpan.TotalMinutes, [int]$global:_LastCommandTimeSpan.Seconds, [int]$global:_LastCommandTimeSpan.Milliseconds)
$fmt = "{1}.{2:D3}s"
If (($global:_LastCommandTimeSpan.TotalSeconds) -Ge 60) {
$fmt = "{0}m{1}s"
}
Write-Host "[" -NoNewLine -ForegroundColor (Get-PromptColor CommandTimeBrackets)
Write-Host ($fmt -f $fmtBuff) -NoNewLine -ForegroundColor (Get-PromptColor CommandTime)
Write-Host "] " -NoNewLine -ForegroundColor (Get-PromptColor CommandTimeBrackets)
}
}
Add-PromptTask CalculateCommandLength {
If ($global:_LastCommandLaunchDate) {
$global:_LastCommandTimeSpan = (Get-Date).Subtract($global:_LastCommandLaunchDate)
$global:_LastCommandLaunchDate = $null
Set-PromptColor CommandTimeBrackets DarkYellow
Set-PromptColor CommandTime Yellow
If (($global:_LastCommandTimeSpan.TotalSeconds) -Ge 30) {
Set-PromptColor CommandTimeBrackets DarkRed
Set-PromptColor CommandTime Red
}
}
}
Add-BuiltinPrompt DHowettPrompt @(
$function:pe_LastCommandRunTime,
$function:pe_NoSeparator,
$function:pe_DevEnvHostname,
$function:pe_Provider,
$function:pe_NoSeparator,
$function:pe_ShortHomePath,
$function:pe_Sigil
)
Add-PromptTask WindowTitlePath {
$title = ""
If($null -ne $Global:DevEnv -and $Global:DevEnv.Name) {
$title += "(" + $Global:DevEnv.Name + ") ";
}
if ($PWD.Provider.Name -ne "FileSystem") {
$title += $PWD.Provider.Name.ToLower()
if ($PWD.ProviderPath[0] -ne "\") {
$title += ":\"
} else {
$title += ":"
}
}
$title += $PWD.ProviderPath.Replace($HOME, "~")
$Host.UI.RawUI.WindowTitle = $title
}
Set-PromptColor Provider DarkMagenta
Set-PromptColor Sigil Green
Set-PromptColor Hostname White
Set-PromptColor DevEnv Green
Set-PromptColor CommandTime Black
Set-PromptColor CommandTimeBrackets Black
# These are already defined by PromptEd
Set-PromptColor Path Magenta
Set-PromptColor Brackets Blue
Set-Prompt DHowettPrompt
Set-PSReadlineKeyHandler "Enter" -ScriptBlock {
$global:_LastCommandLaunchDate = Get-Date
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}
}
New-Alias -Name Eject -Value Eject-Disk
New-Alias -Name ssh -Value klink
New-Alias -Name make -Value mingw32-make
#New-Alias -Name gvim -Value 'C:\Program Files\Vim\vim74\gvim.exe'
Function Unique-Strings {
Param (
[String[]]
$InputStrings
)
If($null -eq $InputStrings) {
$InputStrings = @($input)
}
$Script:n = 0
$InputStrings | Select -Property (
@{Name="S";Expression={$_}},
@{Name="U";Expression={$_.ToUpper()}},
@{Name="I";Expression={$Script:n++; $Script:n}}
) | Sort -Property U -Unique | Sort -Property I | Select -ExpandProperty S
}
Function Enter-DevelopmentEnvironment {
[CmdletBinding()]
......@@ -196,16 +289,6 @@ Function Get-FuzzyChildItem {
New-Alias -Name o -Value Open-FuzzyMatchedItem
New-Alias -Name f -Value Get-FuzzyChildItem
Function Format-Clang {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string[]]$Files
)
& clang-format -i ($Files -Join " ")
}
New-Alias -Name fmt -Value Format-Clang
. "$(Split-Path $PROFILE)\Get-InstalledSoftware.ps1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment