5 ms·
The Z command line utility has saved me a ton of time. It remembers the directories you’ve visited and lets you jump to them with just a few characters. Almost
by dceddia 7y ago
The Z command line utility has saved me a ton of time. It remembers the directories you’ve visited and lets you jump to them with just a few characters. Almost like Chrome’s autocomplete for recently-visited directories (if you’re used to being able to type “g” to go to gmail or “n” for “news.ycombinator.com”...). For instance I can run “z B” and it’ll jump to my ~/Business directory (and “z ss” would do the same).
https://github.com/rupa/z https://github.com/rupa/z
- hombre_fatal 7y agoThis is one of those things I set up a decade ago and it's become such a part of how I use my computer that I'm confused for a moment whenever it's not there. It's one of those rare tools that interacts with my stream of consciousness which is one step away from mind reading.
- mszcz 7y agoDid you mean "(...) almost like _Firefox's_ autocomplete (...)"? I know this is OT but one of the reasons I've switched is history search that actually works.
- lloeki 7y agoI prefer my own kd, which is 40 dead simple LOCs of shell and is predictable since it operates only on dirs you added (which sounds like a chore but is just fine in practice) kd foo $PWD # stores as foo kd f # jumps to foo kd # in a Ruby project subdir, jumps up to where the Gemfile is https://github.com/lloeki/dotfiles/blob/master/shell/kd https://github.com/lloeki/dotfiles/blob/master/shell/kd
- lloeki 7y agoJust updated kd with a long-time feature I wanted: tty detection! kd f # => jumps to foo echo $(kd f) # => outputs foo's path # some creative, if nonsensical, examples: cp some/file $(kd foo)/app/controllers/whatevs cp $(kd bar)/Gemfile $(kd foo)/Gemfile kd foo && cd app/controllers && cp $(kd)/config/whatever . This is useful and possible because kd's output is stable and predictable: it always returns the last prefix match of the kdrc file (or, without argument, the project's top-level dir), and it returns non-zero rc on failure. Plus zsh will even gladly expand the result on <TAB> for double checking.
- RMPR 7y agoFor this particular case, I use a ncurses based file manager: ranger
- fdw 7y agoInstead of z, I use https://github.com/wting/autojump https://github.com/wting/autojump, which is written in Python. This has the benefit that you can call it from outside the shell, too. Since I also love ranger as a file manager, I wrote my own integration of both: https://github.com/fdw/ranger-autojump https://github.com/fdw/ranger-autojump . It remembers where I went in ranger, and I can also call autojump in ranger.
- sandreas 7y agoHehe since i got to know 'cd -' which changes back to the last directory i did not miss this feature - but it sounds interesting, and i should try it out.
- austinjp 7y agoYou're going to love pushd and popd.
- leu-mas 7y agoanother popular alternative I see mentioned a lot https://github.com/wting/autojump https://github.com/wting/autojump > autojump is a faster way to navigate your filesystem. It works by maintaining a database of the directories you use the most from the command line.
- GrantZvolsky 7y agoI couldn't do without a 'bookmarks' feature that I implemented for my terminal. It's triggered with `Alt+b`: 1. Scan an eternal history file for `cd` with absolute path except for /tmp/* 2. Sort and filter out duplicates 3. Call fzf and let user pick the desired result 4. Upon selection don't enter the directory but instead type `cd <selection>` into the prompt so that the user can navigate further using <Tab>. What's nice about this approach is that it automatically builds your bookmarks, but only from `cd` commands where you deliberately used an absolute path. Here's the code. It has some prerequisites (fzf[0] and ~/.eternal_bash_history[1]) and probably only works with my terminal (Xfce Terminal); it took a bit of tinkering to get it to work. # ~/bashrc.d/aliases.sh __b() { # bookmarks; props to fzf for providing examples of READLINE configuration local selected="cd "$(cat ~/.bash_eternal_history | grep '^cd /' | egrep -v '\.\.|/tmp' | awk '{print $2}' | sort | uniq | fzf --exact) READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}" READLINE_POINT=$(( READLINE_POINT + ${#selected} )) } bind -m vi-insert -x '"\eb": "__b"' 2>/dev/null [0]: https://github.com/junegunn/fzf https://github.com/junegunn/fzf [1]: https://stackoverflow.com/a/19533853 https://stackoverflow.com/a/19533853