Last active
March 14, 2019 16:19
-
-
Save tats-u/32cb142387c87ccc2a5114142d6d3e13 to your computer and use it in GitHub Desktop.
Change the prompt of your PowerShell to one like Bash
This file contains 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
function prompt() { | |
$return_code = $? | |
$domain_and_name = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name | |
$absolute = (Get-Location).Path | |
$esc = "$([char]27)" | |
$reset = $esc + "[0m" | |
$nas_prefix = 'Microsoft.PowerShell.Core\FileSystem::' | |
$is_root = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator) | |
$prompt_sign = if ($is_root) { Write-Output '#' } else { Write-Output '$' } | |
return "${esc}[1;36mPS${reset}" ` | |
+ " " ` | |
+ "${esc}[1;32m$(Split-Path $domain_and_name -Leaf)" ` | |
+ "@" ` | |
+ "$(Split-Path $domain_and_name -Parent)${reset}" ` | |
+ ":" ` | |
+ "${esc}[1;34m$(if ($absolute.StartsWith($env:USERPROFILE)) { Write-Output $absolute.Replace($env:USERPROFILE, '~') } elseif ($absolute.StartsWith($nas_prefix)) { Write-Output $absolute.Replace($nas_prefix, '') } else { Write-Output $absolute })${reset}" ` | |
+ "$(if($return_code) { Write-Output $prompt_sign } else { Write-Output "${esc}[1;31m${prompt_sign}${reset}" })" ` | |
+ " " | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample image:
![sample image](https://user-images.githubusercontent.com/12870451/54373245-4235d480-46c0-11e9-80ea-b8fdfcf6ee55.png)