Behavior of cd -PassThru

Topics: Developer Forum, User Forum
Mar 22, 2008 at 5:18 AM
Edited Mar 22, 2008 at 10:42 AM
After installing v1.1.1 I noticed that the default behavior of cd commands is to display the new path and if the -PassThru parameter is specified nothing is displayed. Looking at the definition of the cd function, it appears that on line 202 there is a ! operator where there shouldn't be one:

if (!$PassThru) { (Get-Location).ProviderPath }

Have I misinterpreted the code?

I also found that using some of the shortcuts (e.g. cd- and cd+) always displays the new location. I haven't figured out why this is happening yet, though.

Thanks,
David
Coordinator
Mar 26, 2008 at 3:45 PM
Yeah, the code above is what prints out the path to the console. The current code is a bit different and might make this a bit clearer:

if ($PassThru) { 
    $PassThruObject
}
else {
    (Get-Location).ProviderPath 
}
Oct 2, 2009 at 3:42 AM

I just installed PSCX 1.2 and noticed the change you describe.  It should have been obvious to me by reading the code above that it will always display something but somehow I missed that.  This solution makes the usage more verbose than I'd like.  I've modified it like this which works very well:

if ($PassThru) {
    $PassThruObject
}
elseif ($Pscx:Preferences['VerboseCd']) {
    (Get-Location).ProviderPath
}

Thanks for the help.
David