...
 
Commits (9)
......@@ -37,15 +37,20 @@ Function pe_ShortHomePath {
}
Function pe_NestedPromptLevel {
If ($NestedPromptLevel -Gt 0) {
$PSLevel = [int]$Env:_DH_PS_NESTING_LEVEL
If ($NestedPromptLevel -Gt 0 -Or $PSLevel -Gt 0) {
Write-Host "<" -NoNewLine -ForegroundColor DarkYellow
If ($PSLevel -Gt 0) {
Write-Host "$PSLevel." -NoNewLine -ForegroundColor White
#Write-Host "$([char]0x1b)[38;5;208m$PSLevel.$([char]0x1b)[0m" -NoNewLine
}
Write-Host "$NestedPromptLevel" -NoNewLine -ForegroundColor Yellow
Write-Host "> " -NoNewLine -ForegroundColor DarkYellow
}
}
Function pe_Sigil {
If($IsWindows) {
If($Null -eq $IsWindows -Or $IsWindows) {
if((
New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
......@@ -59,32 +64,31 @@ Function pe_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
$lastCommand = Get-History -Count 1
If ($global:_LastHistoryId -Ne $lastCommand.Id) {
$duration = $lastCommand.EndExecutionTime.Subtract($lastCommand.StartExecutionTime)
If ($duration.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]$duration.TotalMinutes, [int]$duration.Seconds, [int]$duration.Milliseconds)
$fmt = "{1}.{2:D3}s"
If (($duration.TotalSeconds) -Ge 60) {
$fmt = "{0}m{1}s"
}
$bracketColor = Get-PromptColor CommandDurationBracketsMedium
$timeColor = Get-PromptColor CommandDurationMedium
If (($duration.TotalSeconds) -Ge 30) {
$bracketColor = Get-PromptColor CommandDurationBracketsHigh
$timeColor = Get-PromptColor CommandDurationHigh
}
Write-Host "[" -NoNewLine -ForegroundColor $bracketColor
Write-Host ($fmt -f $fmtBuff) -NoNewLine -ForegroundColor $timeColor
Write-Host "] " -NoNewLine -ForegroundColor $bracketColor
}
$global:_LastHistoryId = $lastCommand.Id
}
}
......@@ -107,18 +111,13 @@ Set-PromptColor Sigil Green
Set-PromptColor Hostname White
Set-PromptColor DevEnv Green
Set-PromptColor CommandTime Black
Set-PromptColor CommandTimeBrackets Black
Set-PromptColor CommandDurationMedium Yellow
Set-PromptColor CommandDurationBracketsMedium DarkYellow
Set-PromptColor CommandDurationHigh Red
Set-PromptColor CommandDurationBracketsHigh DarkRed
# These are already defined by PromptEd
Set-PromptColor Path Magenta
Set-PromptColor Brackets Blue
Set-Prompt DHowettPrompt
If ($null -ne (Get-Module PSReadline)) {
Set-PSReadlineKeyHandler "Enter" -ScriptBlock {
$global:_LastCommandLaunchDate = Get-Date
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}
}
......@@ -9,3 +9,20 @@ Set-PSReadlineKeyHandler "Ctrl+Backspace" BackwardKillWord
Set-PSReadlineKeyHandler "Ctrl+LeftArrow" BackwardWord
Set-PSReadlineKeyHandler "Ctrl+RightArrow" NextWord
Set-PSReadlineKeyHandler "Tab" MenuComplete
# Work around an RS5/PSReadline-2.0.0+beta2 bug (Spacebar is not marked Vital)
Set-PSReadlineKeyHandler "Shift+SpaceBar" -ScriptBlock {
[Microsoft.Powershell.PSConsoleReadLine]::Insert(' ')
}
If ($PSEdition -eq "Core") {
Set-PSReadlineOption -Colors @{
Type = "`e[38;5;85m";
String = "`e[38;5;130m";
Number = "`e[38;5;220m";
Variable = "`e[38;5;191m";
Command = "`e[38;5;117m";
Operator = "`e[38;5;213m";
Parameter = "`e[38;5;239m";
}
}
......@@ -33,4 +33,18 @@ Function Enter-DevelopmentEnvironment {
}
}
Register-ArgumentCompleter -CommandName Enter-DevelopmentEnvironment -ParameterName Name -ScriptBlock {
Param($cmd, $param, $word, $ast, $pos)
Get-ChildItem (Split-Path $Profile | Join-Path -ChildPath "Dev") -EA SilentlyContinue |
Where-Object Name -Like "$word*" |
Sort-Object |
ForEach-Object {
$name = $_.Name
If ($name -Like "*.ps1") {
$name = $name -Replace "\.ps1$",""
}
[System.Management.Automation.CompletionResult]::new($name, $name, "ParameterValue", $name)
}
}
New-Alias -Name dev -Value Enter-DevelopmentEnvironment
If ($null -Ne (Get-Command -All gvim -EA:Ignore)) {
New-Alias -Name vim -Value gvim
# Only use gvim in a local session!
If ([String]::IsNullOrEmpty($Env:SSH_CONNECTION)) {
If ($null -Ne (Get-Command -All gvim -EA:Ignore)) {
New-Alias -Name vim -Value gvim
}
}
......@@ -3,13 +3,14 @@ Function Search-SourceCode {
Param (
[Parameter(Mandatory=$True, ValueFromPipeline=$True, ValueFromRemainingArguments=$True)]
[string[]]$Pattern,
[string]$Path,
[string[]]$Path,
[string]$Filter,
[string[]]$Include = ("*.c", "*.cpp", "*.h", "*.java", "*.m", "*.mm", "*.cc"),
[string[]]$Exclude,
[switch]$CaseSensitive = $False
)
Get-ChildItem -Path:$Path -Filter:$Filter -Include:$Include -Recurse |
Get-ChildItem -Path:$Path -Filter:$Filter -Include:$Include -Exclude:$Exclude -Recurse |
Select-String -Pattern:$Pattern -CaseSensitive:$CaseSensitive
}
......
......@@ -8,3 +8,17 @@ Function Enter-Subshell {
}
New-Alias -Name ss -Value Enter-Subshell
Function Enter-NestedShell {
([int]$Env:_DH_PS_NESTING_LEVEL)++
Push-Location -StackName:"SubshellStack" -Path:$Path > $Null
If ($PSEdition -Eq "Desktop") {
& powershell.exe -NoLogo -NoExit
} Else {
& pwsh.exe -NoLogo -NoExit
}
Pop-Location -StackName:"SubshellStack" > $Null
([int]$Env:_DH_PS_NESTING_LEVEL)--
}
New-Alias -Name nest -Value Enter-NestedShell
ForEach($i In (Get-ChildItem (Join-Path (Split-Path $Profile.CurrentUserAllHosts) profile.d) -Filter:*.ps1 -EA:Ignore)) {
$Script:DH_PROFILE_VARS = @{
ProfileTimings = @();
};
ForEach($i In (Get-ChildItem (Join-Path (Split-Path $Profile.CurrentUserAllHosts) profile.d) -Filter:*.ps1 -EA:Ignore)) {
$start = Get-Date
. ($i.FullName)
$end = Get-Date
$Script:DH_PROFILE_VARS.ProfileTimings += @{
Name = $i.Name;
Duration = $end.Subtract($start);
}
}
Function Get-ProfileTimings {
$total = 0
ForEach($v in $Script:DH_PROFILE_VARS.ProfileTimings) {
$ms=$v.Duration.TotalMilliseconds
$color=[ConsoleColor]::Green
if ($ms -gt 100) {
$color=[ConsoleColor]::Yellow
}
if ($ms -gt 1000) {
$color=[ConsoleColor]::Red
}
Write-Host -Fore $color ("{0,-10:F04}ms" -f $ms) -nonewline
Write-Host -Fore Cyan " | " -nonewline
Write-Host -Fore White $v.Name
$total+=$ms
}
Write-Host -Fore Cyan "-------------+"
Write-Host -Fore White ("{0,-10:F04}ms" -f $total) -NoNewLine
Write-Host -Fore Cyan " | " -NoNewLine
Write-Host -Fore White ("{0} entries" -f $Script:DH_PROFILE_VARS.ProfileTimings.Length)
}