Created
October 19, 2016 13:41
-
-
Save PrateekKumarSingh/1f6800391333b630e736542a407e043e to your computer and use it in GitHub Desktop.
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 to Get Custom Directory path | |
Function Get-CustomDirectory | |
{ | |
[CmdletBinding()] | |
[Alias("CDir")] | |
[OutputType([String])] | |
Param | |
( | |
[Parameter(ValueFromPipeline=$true,Position=0)] | |
$Path = $PWD.Path | |
) | |
Begin | |
{ | |
#Custom directories as a HashTable | |
$CustomDirectories = @{ | |
$env:TEMP ='Temp' | |
$env:APPDATA ='AppData' | |
"C:\Users\Prateek\Desktop" ='Desktop' | |
"C:\Users\Prateek\Desktop\Blog" ='BlogDump' | |
"C:\Users\Prateek\Documents" ='MyDocuments' | |
"C:\Users\Prateek\Downloads" ='Downloads' | |
"C:\Users\Prateek\Desktop\Blog\Slackathon" ="Slack" | |
"C:\Data\Powershell\Scripts" ='Root' | |
'C:\Data\Powershell\Tutorials' ='Tutorials' | |
} | |
} | |
Process | |
{ | |
Foreach($Item in $Path) | |
{ | |
$Match = ($CustomDirectories.GetEnumerator().name | ?{$Item -eq "$_" -or $Item -like "$_*"} |` | |
select @{n='Directory';e={$_}},@{n='Length';e={$_.length}} |sort Length -Descending |select -First 1).directory | |
If($Match) | |
{ | |
[String]($Item -replace [regex]::Escape($Match),$CustomDirectories[$Match]) | |
} | |
ElseIf($pwd.Path -ne $Item) | |
{ | |
$Item | |
} | |
Else | |
{ | |
$pwd.Path | |
} | |
} | |
} | |
End | |
{ | |
} | |
} | |
# Custom Powershell Host Prompt() | |
Function Prompt | |
{ | |
Write-Host "I " -NoNewline; Write-Host "$([char]9829) " -ForegroundColor Red -NoNewline; Write-Host "PS " -NoNewline | |
Write-Host $(Get-CustomDirectory) -ForegroundColor Green -NoNewline | |
Write-Host " >_" -NoNewline -ForegroundColor Yellow | |
return " " | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment