Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm using Powershell in Windows 7. How to configure Powershell so that it only displays the current folder name (instead of the full path) in the shell prompt?

For example, Instead of C:\folder\directory\name>, I want name>.

share|improve this question
add comment

2 Answers

up vote 11 down vote accepted

You have to customize the prompt function in your PowerShell profile (%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1); it may be blank or even not exist if you have never modified it before.

  1. Open your profile (e.g., open the aforementioned file or while in PowerShell, Notepad $profile)

  2. Add the following to your profile:

    function prompt {
      $p = Split-Path -leaf -path (Get-Location)
      "$p> "
    }
    
  3. Save the profile

  4. Restart PowerShell

share|improve this answer
    
Not quite right. [System.IO.Directory]::GetCurrentDirectory() does not represent powershell's current location, but rather the process working directory, which are not always the same. Replace with Get-Location –  zdan Jul 9 '12 at 20:57
    
+1, but I would use get-location instead of GetCurrentDirectory. Remember that PowerShell does not always mean the file system. Using the registry snap-in, I could use cd hkcu: and now the prompt would be totally off. –  vcsjones Jul 9 '12 at 20:58
    
I don't use PowerShell (it is excruciatingly slow on my system), so I am not familiar with its intricacies. I have changed the call and improved the formatting. –  Synetech Jul 9 '12 at 21:01
    
@Synetech oops, looks like my edit killed your change. –  vcsjones Jul 9 '12 at 21:03
    
@vcsjones, no worries, it's fixed now. And thanks for telling me about the eight-space thing, I have never seen that (and been quiet frustrated). Now I have to find the one or two times in the past that I could have used it and make the change. –  Synetech Jul 9 '12 at 21:06
show 4 more comments

The below single line works fine for me

(Get-Location | Get-Item).Name

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.