Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Created October 19, 2016 13:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save PrateekKumarSingh/1f6800391333b630e736542a407e043e to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/1f6800391333b630e736542a407e043e to your computer and use it in GitHub Desktop.
# 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