Spend less time CD'ing around directories with the PowerShell Z shortcut
Everyone has a trick for moving around their computer faster. It might be a favorite shell, a series of aliases or shortcuts. I like using popd and pushd to quickly go deep into a directory structure and return exactly where I was.
Another fantastic utility is simply called "Z." There is a shell script for Z at https://github.com/rupa/z that's for *nix, and there's a PowerShell Z command (a fork of the original) at https://github.com/vincpa/z.
As you move around your machine at the command line, Z is adding the directories you usually visit to a file, then using that file to give you instant autocomplete so you can get back there FAST.
If you have Windows 10, you can install Z in seconds like this:
C:\> Install-Module z -AllowClobber
Then just add "Import-Module z" to the end of your Profile, usually at $env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Even better, Z works with pushd, cd, or just "z c:\users\scott" if you like. All those directory changes and moves will be recorded it the Z datafile that is stored in ~\.cdHistory.
What do you think? Do you have a favorite way to move around your file system at the command line?
Sponsor: Get the latest JetBrains Rider preview for .NET Core 2.0 support, Value Tracking and Call Tracking, MSTest runner, new code inspections and refactorings, and the Parallel Stacks view in debugger.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
I once built myself something similar, where I had to maintain the list of popular destinations myself.
This is much better and it's nice to just be able to import and use it!
But I needed to change the command to "Install-Module -Name z -Scope CurrentUser" as I don't want to use elevated rights every time I start powershell.
And it makes it quiet slow to start the shell.
Install-Module z -AddToProfilefrom a non administrator command line.
I also have variables in my profile for my favorite directories, so I can do things like cd $GithubDir, with tab completion for variable names.
jcommand
https://www.hanselman.com/blog/JumpLocationAChangeDirectoryCDPowerShellCommandThatReadsYourMind.aspx
:-)
This would be a great addition for baked-in behavior in both the command line and Windows Explorer. Most of the time I use Explorer, and its recent places list has always been very flaky and unreliable. It would a lot nicer if you could type in the address bar and have it give MRU suggestions like this.
I mark a favorite location with "m secretproject" and then I can forever jump to it with "j secretproject" or "j se".
It lives here: https://github.com/secretGeek/markjump/blob/master/README.md
Install-Module -Name "z" -Scope "CurrentUser"
appears to work if you don't want to use an admin prompt.
Install-Module -Name z -Scope CurrentUser; echo "Import-Module z" > $env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
C:\> grr cd RepoZ
D:\Develop\GitHub\RepoZ>
Comments are closed.
It keeps the directories in a session variable - and implements the
Which will change to the previous directory.
and the
Which will cd to your $home directory.