How to make PowerShell shorten the long path of the current directory.

Are you getting less space on the PowerShell due to the long path of the current directory?

You can increase the signal to noise ratio by hiding that long path. How?

Follow the steps:

  • Navigate to PowerShell and type $profile.
  • It will give you a path to the PowerShell profile file.
  • Navigate to the directory of that PowerShell profile file.
    It was “C:\Users\{user}\Documents\WindowsPowerShell” for me.
  • Check if the file “Microsoft.PowerShell_profile.ps1” exists on the disk.
  • If NOT then create one “Microsoft.PowerShell_profile.ps1”.
  • Open “Microsoft.PowerShell_profile.ps1” file.
  • Paste the following code in it and save.
function prompt {
  $p = Split-Path -leaf -path (Get-Location)
  "$p> "
}
  • Restart PowerShell.
  • It will show the current folder name only.

Dattatraya Kale

Aspiring agile software craftsman, clean code, polyglot, in love with different programming paradigm. I am on a never-ending journey towards mastery of software.

One thought to “How to make PowerShell shorten the long path of the current directory.”

Leave a Reply