Sponsored By
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
Comment on this post [18]
Share on or or use the Permalink
So this inspired me to publish my: Set-LocationEx.ps1.
It keeps the directories in a session variable - and implements the
cd -
Which will change to the previous directory.
and the
cd
Which will cd to your $home directory.
Bjarke L
Promptly installed.
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!
If I don't have that $env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 file, should I create it?
Kolja Lampe
Just creating the file worked.
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.
Kolja Lampe
I use Go-Shell for basically the same thing, though it is a manual process to set up the shortcuts. But it does allow me to type gd documents and it will put me in my "documents" folder. This module does sound interesting though...
Or just use
Install-Module z -AddToProfile
from a non administrator command line.
I use the PowerShell Community Extensions, which provide the cd - and cd + commands to go to backwards/forwards in location history.
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.
I use Jump Location, which I first learned about from another of your posts:
https://www.hanselman.com/blog/JumpLocationAChangeDirectoryCDPowerShellCommandThatReadsYourMind.aspx
:-)
Adam H
PSReadine (in the box in PowerShell 5+ but installable for previous versions) supports Ctrl+R that serves me pretty well.
Awesome tip! As for what I use, I have several small SlickRun shortcuts with my most common directories. The only issue with this method is that I get a new shell every time, not to change in place.
Claudio
Nice!
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.
Sam
I use a little library I wrote called "markjump".
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
Something like
Install-Module -Name "z" -Scope "CurrentUser"
appears to work if you don't want to use an admin prompt.
Jon
Here's a one-liner that works
Install-Module -Name z -Scope CurrentUser; echo "Import-Module z" > $env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Great tip indeed, thanks for that. As I mostly use the command line for git, I use a tool called RepoZ to jump from repository to repository directly by just using the git repository name like: grr cd RepoName
C:\> grr cd RepoZ
D:\Develop\GitHub\RepoZ>
Tank
I have tried ZLocation a few months ago but found it does not work well together with posh-git. Therefore I am using the slightly inferior version of it called Jump-Location: https://github.com/tkellogg/Jump-Location
Christoph Bergmeister
Scott, how do you (i.e. tools for recording and converting) make the shell window Animated GIFs in your posts? They really shine in some scenarios versus typing and formatting the code in HTML.
Eddie Butt
Comments are closed.