-
-
Save aldrichtr/449cf361cb406a23bd8538f3dd9d9fdb to your computer and use it in GitHub Desktop.
Show a moon spinner on the tab title using DynamicTitle PowerShell module
This file contains hidden or 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
| #Requires -Modules DynamicTitle | |
| $commandStartJob = Start-DTJobCommandPreExecutionCallback -ScriptBlock { | |
| param($command) | |
| (Get-Date), $command | |
| } | |
| $promptJob = Start-DTJobPromptCallback -ScriptBlock { | |
| (Get-Date) | |
| } | |
| $initializationScript = { | |
| $spinnerSymbols = @('π', 'π', 'π', 'π', 'π', 'π', 'π', 'π') | |
| $spinnerSymbolIndex = 0 | |
| } | |
| $update = { | |
| param($commandStartJob, $promptJob) | |
| $commandStartDate, $command = Get-DTJobLatestOutput $commandStartJob | |
| $commandEndDate = Get-DTJobLatestOutput $promptJob | |
| if ($null -ne $commandStartDate) { | |
| if (($null -eq $commandEndDate) -or ($commandEndDate -lt $commandStartDate)) { | |
| $commandDuration = (Get-Date) - $commandStartDate | |
| $isCommandRunning = $true | |
| } | |
| else { | |
| $commandDuration = $commandEndDate - $commandStartDate | |
| } | |
| } | |
| if ($command) { | |
| $command = $command.Split()[0] | |
| } | |
| $spinner = $spinnerSymbols[0] | |
| if ($commandDuration) { | |
| if ($commandDuration.TotalSeconds -gt 1) { | |
| $commandSegment = 'β [{0}]-β{1}' -f $command, $commandDuration.ToString('mm\:ss') | |
| if ($isCommandRunning) { | |
| $script:spinnerSymbolIndex = ($script:spinnerSymbolIndex + 1) % $spinnerSymbols.Count | |
| $spinner = $spinnerSymbols[$script:spinnerSymbolIndex] | |
| } | |
| } | |
| else { | |
| $script:spinnerSymbolIndex = 0 | |
| } | |
| } | |
| '{0} PowerShell {1}' -f $spinner, $commandSegment | |
| } | |
| $params = @{ | |
| ScriptBlock = $update | |
| ArgumentList = $commandStartJob, $promptJob | |
| InitializationScript = $initializationScript | |
| } | |
| Start-DTTitle @params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment