Developing on Staxmanade

More than slightly modified “CD” command for PowerShell

A while back I wrote about a Slightly modified “CD” Command for PowerShell.
Since that point, I’ve made a number of updates and would like to share them.
The first change I made was to move the “CD” script in that post to a new location. I’ve greatly extended how I setup my development environment and how my PowerShell environment is initialized.
If you’re interested in how I setup my PS profile, take a look at the readme. Combine the setup with some Chocolatey and some BoxStarter and you’re on your way to an amazingly automated development environment setup.
Now on to the features I’ve added to the CD command.
  • I often would do something like “CD $Profile” (which is a no-go because that is a file not a directory, but my intent was to get into the directory where the $Profile file lived).

    So I updated it so if you try to CD to a file, it will just take you to the directory where the file resides.
  • If you try to CD into a folder that doesn’t exist, it now prompts you to create it. You could bypass the prompt with a -force|-f flag.image
  • Lastly I fixed an issue reported by a commenter in the previous post about trying to CD into a folder with the same name as a history index. If you had a folder named “4” and you typed “CD 4” it previously wouldn’t take you the 4 directory, but instead lookup item 4 in your CD history and take you there. Now if you specify a number and that number lives in the current directory it will take precedence over your history value. (To be fair, I only added this feature, and even since I originally wrote about the CD command I have yet to run into a need for this case. Probably because I don’t name my directories with numbers).
Something I had only recently noticed is this script appears to work with other PowerShell drive providers. I only did a cursory test but can CD into the HKLM:\Software\MyTestFolderThatShouldntExist and it will prompt to create the ‘folder’. If I say yes, I end up with a new registry folder. Smile Not sure how useful that is, but with the abstraction layer PowerShell drives give us it’s interesting.

If you’d like to grab just the CD script you can download it here.
https://github.com/staxmanade/DevMachineSetup/blob/master/GlobalScripts/Change-Directory.ps1

Happy system navigation with PowerShell.