6 ms·
Behold z, the unsung jewel that rethinks shell navigation
- hprotagonist 6y agoz and fzf are among the first things i install on a new account.
- nijaru 6y agoA similar tool that saves me immeasurable amounts of time is fasd[0]. I started using it as a part of prezto[1], which is similar to oh-my-zsh, and have never gotten around to trying any other solutions such as z. [0] https://github.com/clvv/fasd https://github.com/clvv/fasd [1] https://github.com/sorin-ionescu/prezto https://github.com/sorin-ionescu/prezto
- wef 6y agoMore discussion of the topic: https://www.reddit.com/r/linux/comments/lbfhjc/a_better_cd/ https://www.reddit.com/r/linux/comments/lbfhjc/a_better_cd/
- Xavdidtheshadow 6y agoThis sounds just like autojump (typically run using `j`) to me: https://github.com/wting/autojump https://github.com/wting/autojump Agree that it's an invaluable piece of software!
- iFreilicht 6y agoAny idea what the differences are? Am I missing anything by keeping to use autojump?
- loa_in_ 6y agoNo, it seems from the article it's a clone.
- simlevesque 6y agoSeems like autojump used to work with regexps but now it's something custom. Z works with regexps.
- hyperpallium2 6y agofunfact: vim does this with **, and tab-complete. For navigating between parallel directory structures (src/ and test/), I made an awful hack called c-, that sed subs src/ for test/ and vice versa on pwd. A fluke grade.
- JNRowe 6y agoWhen actually inside vim Tim Pope's excellent vim-projectionist has a wonderfully useful feature for flipping between various related files(:h projectionist-alternate). The whole plugin is really cool, it makes it so simple to configure project specific working environments with it. https://github.com/tpope/vim-projectionist https://github.com/tpope/vim-projectionist
- domoritz 6y agoI am now using https://github.com/ajeetdsouza/zoxide https://github.com/ajeetdsouza/zoxide (in Rust) and it works really well.
- yewenjie 6y agoI use zoxide - a modern z written in Rust. https://github.com/ajeetdsouza/zoxide https://github.com/ajeetdsouza/zoxide
- SeanA208 6y agoI use https://github.com/clvv/fasd https://github.com/clvv/fasd which has all the functionality of z but with some other goodies as well.
- enricozb 6y agoIs there some functionality that `z` offers that fzf doesn't? I have a keybinding that essentially does `open $(fd | fzf)`, and that is how I go _anywhere_ in my file system. Completely changed how I use the shell. I personally find that fzf is better because I can see where I'm going to end up before I accept the operation.
- Graziano_M 6y agoBesides z being much faster (looking through a sorted list of directories visited instead of recursively walking from the current directory) your snippet looks from the cwd
- enricozb 6y agoThis is a fair point. I usually only "jump" from directories that have at most 500k files, and the median is way closer to ~500 files. Even in the worst cases, at least with my i7 NUC and using fd instead of find, it's less than 500ms to load the entire list into fzf.
- Graziano_M 6y agoYep, that's fair. I use fzf along with z. I use z usually to switch projects (and I work in Go, so many are in GOPATH and annoying to CD to manually) but I use fzf both inside and outside of vim to open individual files.
- JohnBooty 6y agoI personally find that fzf is better because I can see where I'm going to end up before I accept the operation. I agree that's a must-have feature. Luckily z does it as well. Type `z foo` and hit tab. If there's a single match, "foo" will be expanded in place to the proper path. If there are multiple matches, you can choose from a list of paths. So, no mystery navigation (unless you want it) -- you can always see where you're going.
- jnurmine 6y agoWith Bash I use "pushd .", "dirs" and "pushd +1"/"pushd -1". I guess that's not quite as advanced as z or fasd though!
- JNRowe 6y agoNot for you, but perhaps for others who also like that behaviour. With zsh you can enable the auto_pushd option, which makes cd manipulate the directory stack itself. You could probably simply alias cd as pushd too under zsh too, but in bash that would break cd's argument handling.
- ur-whale 6y agocd is yahoo circa 1999 (hierarchical organization of information) z is Google (just give me what I want based on a short description of its name). z is amazing.
- kzrdude 6y agoI'm mildly skeptical of any shortcuts that are based on "learning habits". I've already gotten enough of user interfaces that move items based on use all the time (The spotify playlist list is the worst offender - playlists move up and down in rank after every use, so there is never any spatial memory, startled every time).
- andrewflnr 6y agoIt's very well hidden, but (at least on Android) there is an option to sort alphabetically. I was quite annoyed until I googled it and found out how to do it. I can't find it in the UI now despite having done it before... Anyway, I fully agree.
- sjburt 6y agoYou press z, type a few letters and then hit tab until you get the thing you want. It's not spatial. If you use ctrl-r frequently it's similar.
- kleiba 6y agoIs there any advantage over CTRL-R?
- reeestandard 6y agoWith ctrl-R you'd presumably need a bunch of absolute path navigation commands in the past, with z you don't need to worry about that. There may be more clashes, like picking up on filenames instead of directories. Typing `z res` or whatever is also a bit faster than hitting ctrl-R then `res`.
- kzrdude 6y agoThe examples show "z someinput" and enter, so then going to some place based on learned location for someinput, no? It's not spatial because it's text-based but a similar problem occurs if it can surprise you about which location is going to be used for each input.
- 6y ago
- 1_2__4 6y agoTools like this always make me faintly uncomfortable. The idea is nice, but as a systems guy I would liken it to a mechanic’s toolbox that tries to predict what tool you want and puts it in your hand. Seems like it would be nice except you would need to carefully check what tool you were given to make sure the algo didn’t make a wrong decision and you’re using a wrong-sized wrench or something. I’m not sure I want the fundamental building blocks of my field to be “helpful” like this. I’m much more a fan of naming it easier and faster for computers to do what I want, than I am of computers trying to divine what I want without my explicitly asking for it at this level.
- ilaksh 6y agoIt sounds terrific. Also make sure to check out the fish shell if you haven't before. It's tab completions/up-arrow completions including for cd are really useful in a similar way.
- yoz-y 6y agoI’ve used fish for quite a while but after Many a scripting incompatibility I went back to ohmyzsh. Fish is great if you can port your whole ecosystem into it.
- jibbit 6y agoI find the persistent directory stack of ohmyzsh (easy enough to enable yourself in zsh) easier to use than things like autojump or z, and pretty much makes them unnecessary. I miss this basic functionality in fish (hoping someone will point out that I have overlooked it)
- justinsaccount 6y agodon't forget about CDPATH $ export CDPATH=~/Workspace/src/github.com # in .bashrc $ cd brigad/ops
- paxswill 6y agoIn my experience, CDPATH is a great way to lose hours chasing down errors throughout your scripts.
- JNRowe 6y ago"CDPATH=<str>" without the export will work as you'd want, and won't pollute the environment for subshells and scripts. It is unlikely you really want to export anything listed in the shell variables section of the man page, but yeah everybody does :/ [This message brought to you by https://news.ycombinator.com/item?id=22978770 https://news.ycombinator.com/item?id=22978770]
- justinsaccount 6y agoTIL, thanks :)
- booky2 6y agoI use 'cz' which is like 'cd' but for git workspaces only. Uses fzf to present list of matches. bash source: cz-index () { sudo find -L ~/work -type d -name '.git' | sed 's;/.git$;;' | sort > ~/git-dirs.txt } cz () { cd "$(cat ~/git-dirs.txt | fzf --tiebreak=begin --exact -i -q $1)" }
- kreelman 6y agoI develop apps on Windows, but I use Linux to do lots of my work and automate cumbersome boring tasks where I can (there are still many more to be automated....). I'm constantly amazed at what Windows dev people can get done without a programmable command line. I've seen several thousand line long cmd/bat files to do relatively simple things. They work, which is good. They are a lot of work to maintain though. I find z absolutely wonderful to take away that first hurdle of remembering folders. I can't imagine how Windows devs who don't know Unix can get around easily. They seem to though. Much must be memorised and some tools help. Powershell is getting better, but I think lacks (at least for the moment) the amount of existing code/books/links that shell solutions have. I sometimes hum my version of that old Sting favourite, Oh, I'm an alien, I'm a legal alien I'm a Linux dev in Windows 10.... I'd be interested to hear if there are better/equivalent searching tools easily available on Windows, but z works wonderfully for me.
- Arnavion 6y agoWindows doesn't lack a programmable command line. If the Windows devs around you are writing bat files, they need to be introduced to PowerShell.
- swiley 6y agoPowershell always felt more like a .net REPL than a normal shell to me.
- mariusmg 6y ago> I can't imagine how Windows devs who don't know Unix can get around easily. They seem to though. It's simple, for filesystem operations most Windows people don't use CLI. I use Total Commander for example, which has tabs and bookmarks to quickly navigate around the filesystem.
- flohofwoe 6y agoFor shell scripts that are longer then a handful lines, python is the better alternative IMHO, especially if the scripts need to work across Windows, Linux and macOS. Windows has some nice tricks to connect the UI to the cmdline. For instance you can type "cmd" or "powershell" in the breadcrumbs-bar of an Explorer window, and it opens a terminal at that filesystem location (and the other way around, "start ." on the command line opens an Explorer window in the current directory. Historically, pure command line workflows are somewhat rare on Windows though.
- xiaq 6y agoOr use Elvish, which has builtin directory history :) Directory history is the 3rd demo on the homepage: https://elv.sh/ https://elv.sh/
- jacobsenscott 6y agoz is amazing. z and fish shell are the two biggest shell productivity boosters I've ever used.
- jachee 6y agoOh-my-zsh with the fzf plugin has a lot of navigation-friction removal. cd ~/r/pr/e/de<tab> Becomes cd ~/repos/projectlongname/environments/development It also has built in push/pop, with minus always returning to the previous path, various numbers of dots, up to six I believe, navigating up the tree, and cd - <tab x2> showing interactive breadcrumbs of recent paths for easy as click-and-click navigation.
- lordgrenville 6y agoI think most of this is out of the box OMZ (without the fzf plugin).
- JNRowe 6y agoBuilt-in zsh behaviour in fact, oh-my-zsh just enables some extremely useful non-default options. With a compinit call the directory substring expansion will work. And, with auto_pushd enabled cd fiddles with the directory stack. The ....... behaviour is interesting because it uses a global alias(alias -g) which is an awesome feature for text expansion anywhere in a line, unlike standard aliases which only expand where commands should be given. It means, for example, you can do `readlink -f ......` and it would perform `readlink ../../../../../..`. Aliases on zsh are very powerful indeed. I'm writing this text in the hope it drives at least one person to burn an afternoon on the amazing(but huge) zsh documentation, because the entire thing is full of gems.
- jachee 6y agoI'll add that to my Read-Only Friday. I got tossed directly into the zsh/omz/fzf pool head-first from bash, so the borders of what's what are murky. Definitely some powerful stuff, so far.
- JNRowe 6y agoIn which case, I've won! Seriously though, I think you were probably lucky to have experienced zsh that way. The out of the box experience is incredibly bare. Said as a fellow oh-my-zsh user going back the full twelve years, according to the history of oh-my-zsh's jnrowe theme ;) I do believe there is a lot of useful knowledge to be gained from working back towards zsh first principles though, especially if -- like me -- you spend hours a day alongside the prompt.
- nathias 6y agoI can't imagine moving around without z, the biggest pain with my CLI use is when z isn't working properly and I have to revert to cd-in around ....
- visarga 6y agoNice. I made a similar tool that saves and searches the history by a query string. In order to keep the history separate for each session I save it to a different file. Nothing I type is ever lost, I can always search for it.
- polyrand 6y agoI have been using `z` for some time, and now I can't imagine working without it. I used to have a big list of aliases like: alias pro='cd ~/Projects' Seems trivial, but it was a huge time saver over time. After installing `z` and using it for a few days, I can now keep only the top 3/4 aliases and `z` does the rest. I've been tempted to try more fancy tools like zoxide, but I love the fact that `z` is just a shell script I can easily move around.
- aymericbeaumet 6y agoOP here, thanks for the amazing comments. Some nice projects to look into! As much as I love z, I'm also a fan of fzf, both are really complementary. I'm using this little piece of code (not from me, but cannot find the original source) to fallback to fuzzy search when z fails to find a result or when no args are given: unalias z &> /dev/null z() { [ $# -gt 0 ] && _z "$*" && return cd "$(_z -l 2>&1 | fzf --nth 2.. +s --tac --query "${*##-* }" | sed 's/^[0-9,.]* *//')" || exit 1 } I also use this approach in a few other places in my workflow (git checkout, vim, etc). Expect a blog post covering this in the near future.
- extrememacaroni 6y agowhy would anyone sing a jewel anyway
- eddyg 6y agoNative zsh version: https://github.com/agkozak/zsh-z https://github.com/agkozak/zsh-z (No external tools, so no forking of awk, sort, date, sed, mv, rm, and chown. Plus some stability improvements in terms of race conditions...)