├── screenshot.png ├── README.md └── profile.ps1 /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devblackops/powershell-prompt/HEAD/screenshot.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # powershell-prompt 2 | 3 | This is my prompt. There are many like it, but this one is mine. 4 | 5 | This prompt function and related settings are just a small portion of my PowerShell [profile](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.1). Feel free to copy and adjust as you see fit. 6 | 7 | ![screenshot](./screenshot.png) 8 | 9 | ## Requirements 10 | 11 | > This prompt **requires** a [Nerd Font](https://www.nerdfonts.com/) to be installed and selected in order to show glyphs/icons correctly. If you don't have a nerd font selected, icons will show as an empty box. 12 | 13 | ### Modules used 14 | 15 | | Name | Description | 16 | |------|-------------| 17 | | [NameIt](https://github.com/dfinke/NameIT) | For showing random names in the title bar 18 | | [posh-git](https://github.com/dahlbyk/posh-git) | For showing git status info when in a git directory 19 | | [Terminal-Icons](https://github.com/devblackops/Terminal-Icons) | For pretty file and folder icons 20 | -------------------------------------------------------------------------------- /profile.ps1: -------------------------------------------------------------------------------- 1 | $mods = @( 2 | 'NameIT' 3 | 'posh-git' 4 | 'Terminal-Icons' 5 | ) 6 | Import-Module $mods 7 | 8 | Set-PSReadLineOption -EditMode Emacs -ShowToolTips 9 | Set-PSReadLineOption -PredictionSource History -Colors @{ Selection = "`e[92;7m"; InLinePrediction = "`e[36;7;238m" } 10 | Set-PSReadLineKeyHandler -Chord Shift+Tab -Function MenuComplete 11 | Set-PSReadLineKeyHandler -Chord Ctrl+b -Function BackwardWord 12 | Set-PSReadLineKeyHandler -Chord Ctrl+f -Function ForwardWord 13 | 14 | if ($IsMacOS -or $IsLinux) { 15 | $pathSeparator = '/' 16 | try { 17 | Import-UnixCompleters 18 | } catch { 19 | Install-Module Microsoft.PowerShell.UnixCompletes -Repository PSGallery -AcceptLicense -Force 20 | Import-UnixCompleters 21 | } 22 | } else { 23 | $pathSeparator = '\' 24 | } 25 | 26 | $script:commonDirs = @{ 27 | home = $HOME 28 | docs = [IO.Path]::Combine($HOME, 'OneDrive', 'Documents') 29 | github = [IO.Path]::Combine($HOME, 'OneDrive', 'Documents', 'GitHub') 30 | onedrive = [IO.Path]::Combine($HOME, 'OneDrive') 31 | } 32 | $script:color = @{ 33 | reset = "`e[0m" 34 | red = "`e[31;1m" 35 | green = "`e[32;1m" 36 | yellow = "`e[33;1m" 37 | blue = "`e[34;1m" 38 | grey = "`e[37m" 39 | lightblue = "`e[38;2;102;178;255m" 40 | orange = "`e[38;2;255;144;30m" 41 | } 42 | $script:glyphs = @{ 43 | home = "$($color.blue)`u{f7db}$($color.reset)" 44 | docs = "$($color.Blue)`u{f491}$($color.reset)" 45 | heart = "$($color.Red)`u{2764}$($color.reset)" 46 | stackoverflow = "$($color.orange)`u{f16c}$($color.reset)" 47 | git = "$($color.blue)`u{e0a0}$($color.reset)" 48 | github = "$($color.lightblue)`u{f408}$($color.reset)" 49 | onedrive = "$($color.blue)`u{f8c9}$($color.reset)" 50 | rightArrow = "$($color.blue)`u{25ba}$($color.reset)" 51 | ellipsis = "$($color.reset)`u{2026}$($color.reset)" 52 | normal = "$($color.green)`u{2714}$($color.reset)" 53 | error = "$($color.red)`u{f00d}$($color.reset)" 54 | warning = "$($color.yellow)`u{f071}$($color.reset)" 55 | forwardSlash = " $($color.orange)`u{e216}$($color.reset) " 56 | } 57 | 58 | $global:GitPromptSettings.BeforeStatus = $color.blue + $glyphs.git + "`e[93m[`e[39m" 59 | 60 | function prompt { 61 | # Modifed from @SteveL-MSFT 62 | # https://gist.github.com/SteveL-MSFT/a208d2bd924691bae7ec7904cab0bd8e 63 | 64 | # Determine last command status 65 | $lastExit = $? ? "[$($glyphs.normal)]" : "[$($glyphs.error)]" 66 | $lastCmd = Get-History -Count 1 67 | if ($null -ne $lastCmd) { 68 | $cmdTime = $lastCmd.Duration.TotalMilliseconds 69 | $units = "ms" 70 | $timeColor = $color.green 71 | if ($cmdTime -gt 250 -and $cmdTime -lt 1000) { 72 | $timeColor = $color.yellow 73 | } elseif ($cmdTime -ge 1000) { 74 | $timeColor = $color.red 75 | $units = "s" 76 | $cmdTime = $lastCmd.Duration.TotalSeconds 77 | if ($cmdTime -ge 60) { 78 | $units = "m" 79 | $cmdTIme = $lastCmd.Duration.TotalMinutes 80 | } 81 | } 82 | $lastCmdTime = "$($color.grey)[$timeColor$($cmdTime.ToString('#.##'))$units$($color.grey)]$($color.reset)" 83 | } 84 | 85 | # Display the common folder glyph instead of the path 86 | $dispDir = $executionContext.SessionState.Path.CurrentLocation.Path 87 | $commonDirGlyph = '' 88 | switch ($dispDir) { 89 | {$_.Contains($commonDirs.github)} { 90 | $commonDirGlyph = $glyphs.github 91 | $dispDir = $dispDir.Replace($commonDirs.github, '') 92 | break 93 | } 94 | {$_.Contains($commonDirs.docs)} { 95 | $commonDirGlyph = $glyphs.docs 96 | $dispDir = $dispDir.Replace($commonDirs.docs, '') 97 | break 98 | } 99 | {$_.Contains($commonDirs.onedrive)} { 100 | $commonDirGlyph = $glyphs.onedrive 101 | $dispDir = $dispDir.Replace($commonDirs.onedrive, '') 102 | break 103 | } 104 | {$_.Contains($commonDirs.home)} { 105 | $commonDirGlyph = $glyphs.home 106 | $dispDir = $dispDir.Replace($commonDirs.home, '') 107 | break 108 | } 109 | } 110 | 111 | # Truncate path if too long and just show the last part of it 112 | $maxPathLength = 48 113 | if ($dispDir.Length -gt $maxPathLength) { 114 | $pathParts = ($dispDir -split $pathSeparator) | Where-Object {-not [string]::IsNullOrEmpty($_)} | ForEach-Object { 115 | @{ 116 | name = $_ 117 | length = $_.Length 118 | } 119 | } 120 | $pathLength = 0 121 | $dirsShown = 0 122 | $truncatedPath = '' 123 | for($i = -1; $i -ge ($pathParts.Count * -1); $i--) { 124 | if ($pathLength -le $maxPathLength -and $dirsShown -le 2) { 125 | $truncatedPath = $pathParts[$i].name + '/' + $truncatedPath 126 | $pathLength += $pathParts[$i].length 127 | $dirsShown++ 128 | } else { 129 | break 130 | } 131 | } 132 | $dispDir = $commonDirGlyph + '/' + $glyphs.ellipsis + '/' + $truncatedPath 133 | } else { 134 | $dispDir = $commonDirGlyph + $dispDir 135 | } 136 | 137 | # Pretty slashes 138 | $dispDir = $dispDir.Replace('/', $glyphs.forwardSlash) 139 | $dispDir = $dispDir.Replace('\', $glyphs.forwardSlash) 140 | 141 | $glyphs.stackoverflow + ' ' + $dispDir + $(Write-VcsStatus) + " $lastExit $lastCmdTime" + [Environment]::NewLine + "I $($glyphs.heart) PS $($glyphs.rightArrow) " 142 | } 143 | 144 | # Windows title 145 | $HOST.UI.RawUI.WindowTitle = Invoke-Generate -Template '[adjective] [noun]' --------------------------------------------------------------------------------