Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I use tab completion in Powershell to complete a relative path Powershell converts it into an absolute one. While the absolute paths work it's getting kind of annoying (making my commands really long and making me reshift my focus when I autocomplete). Is there any way to change it to keep the relative paths when tab completing?

share|improve this question
up vote 2 down vote accepted

Customizing PowerShell Tab Expansion

You can customize tab expansion in PowerShell by replacing the "TabExpansion" function. You can get the current contents of the function with {{Get-Content function:TabExpansion}}. This function should return all the results that should be presented to the user.

There are some gotchas to deal with.

Implementing Relative Paths

The default TabExpansion function does not do the path expansion, it lets the PowerShell engine do path expansion, which is the absolute last fall back. So you will need to add path handling to what comes with PowerShell.

A Better Option

I am a contributor to the PowerTab project, which is a rich implementation of tab expansion in PowerShell. It offers relative path support, as well as a ton of other stuff (WMI class names, .NET type names, shares, method signatures, etc.). The work will already be done for you.

Trying Yourself

If you want to try adding this one feature to the default code, you can check out the end of this file, starting with the comment "## Filesystem Completion":

There is quite a bit of PowerTab specific code in that block, but I can help you out if you want to try.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .