Improve PowerShell commandline navigation

tree10

This post is about improving PowerShell in order to ease navigation on the commandline. There are some pretty cool solutions out there which I have added to my profile to be able to move around quicker:

Another one, that I came up with is in order to move down directory paths quickly similar to ‘cd ..’:

$ExecutionContext.SessionState.InvokeCommand.CommandNotFoundAction={
      param($CommandName,$CommandLookupEventArgs)
      #if the command is only dots
      if ($CommandName -match '^\.+$'){
            $CommandLookupEventArgs.CommandScriptBlock={
                  for ($counter=0;$counter -lt $CommandName.Length;$counter++){
                        Set-Location ..
                  }
            }.GetNewClosure()
      }
}

Adding those lines to your profile (I believe v3 is required for this to work) will enable you to move down directory paths quickly by using just dots where the number of dots determines how many levels you move down the folder hierarchy. If you are for example within “PS>c:\test1\test2\test3\test4” the command “…” will move you down 3 levels to “PS>c:\test1”.

shareThoughts


photo credit: dusk tusks via photopin (license)

Advertisements