[HN Gopher] Z - Jump around
___________________________________________________________________
Z - Jump around
Author : lovestaco
Score : 115 points
Date : 2024-01-15 14:38 UTC (2 days ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| m1keil wrote:
| Alternatives: zoxide, autojump, fasd, and probably couple other
| adr1an wrote:
| +1 zoxide
| kseistrup wrote:
| I actually thought the OP was about zoxide, as the latter also
| installs as z.
| olliemath wrote:
| zoxide is great - in fact I tend to just alias cd to zoxide in
| my bashrc
| aquova wrote:
| https://github.com/skywind3000/z.lua was another that I used
| for a long time, although I've lately started using
| https://github.com/jethrokuan/z
|
| A lot of reinventing the wheel in the z space it seems
| ChatGTP wrote:
| Been using for probably 8 years, amazing
| hiAndrewQuinn wrote:
| Theory: The likelihood of me using a command line tool goes down
| roughly exponentially with the number of keystrokes I have to
| make to call.
|
| Z is really good in this regard, but I still find myself
| relatively reaching for fzf's Alt+C keybinding, as I outlined in
| https://andrew-quinn.me/fzf way back. I think I need to come
| across some killer thing `z` does that I suddenly can't live
| without to overcome the activation energy.
| tambourine_man wrote:
| Map it to whatever shortcut pleases you. It's your shell :)
|
| I use this tiny function: Z() { [ $#
| -gt 0 ] && _z "$*" && return cd "$(_z -l 2>&1 | fzf
| --height 40% --nth 2.. --reverse --inline-info +s --tac --query
| "${*##-* }" | sed 's/^[0-9,.]* *//')" }
| berkes wrote:
| I'll avoid any tools or software that "squats" the one, two or
| three letter space. Almost all one and many of the two-letters
| are already "taken" by some script, alias or both. "z" is
| hibernate for me.
|
| e.g. a timetracker tool "squatted" the "t". _I 'm_ the one to
| decide if this tool is that important to get a one-letter. In
| this case I had to hack around, fork even, to be able to use t
| (which is my todo.txt stuff: t, tt, ta, tl, tp, etc) and to use
| the timetracker (b - no idea why I started using the b for
| this, decades ago: b, bl, bs, etc).
|
| If a developer of a tool decides to "squat" one of the 27
| letters in the alphabet, I think they have delusions of
| grandeur: You are quite certainly not building one of the 27
| most important tools ever built.
| folkrav wrote:
| Wouldn't this easily be solved by an alias or setting your
| script's directory earlier in your $PATH in your shell's RC
| file? I'm not sure how it's becoming an issue at all. It's
| just an executable name, in the end, you control your
| environment.
| berkes wrote:
| Yes, fiddling with the $PATH works, until it doesn't.
|
| In this case the app was installed via RBENV, so it works
| but only if I decide that all of the RBENV stuff must be
| after anything else, which breaks some other hacks/tricks.
| So it would work, until I forget about it and years later
| need some rbenv-installed tool to have precedence over
| something that was globally installed. After which that
| alias I forgot about now suddenly breaks.
|
| I hate it when I'm working on A and get distracted because
| somehow now B fails and some rabbit hole is luring me in. I
| just want to check my TODO's for today: not fiddle around
| with $PATHS and aliases.
|
| Aliasing somewhat helps, but is clumsy too:
|
| alias b=t alias t=todotxt alias bl=b list --all
|
| Sure, better organization solves this. But everything would
| be so much easier if the person writing "t" had stopped and
| rather just taken 'timetrack', 'ttrack', trac or whatever
| instead of "t". Somehow we probably won't like it if such a
| tool suddenly takes over "tr" or "time" either. I feel the
| same about "t".
| shrx wrote:
| There's also unalias.
| sestep wrote:
| What is the 27th letter?
| berkes wrote:
| Sorry, Dutch here, We use the IJ, which isn't officially a
| separate letter, but somehow I learned we have 27 letters
| (when sorting, the IJ comes before the Z. When
| capitalizing, IJsselmeer, is right, Ijsselmeer is wrong). ]
|
| 26 would be for the English alphabet and therefore the
| terminal. I was mistaken.
| Sharparam wrote:
| You don't have to write the I and J separately, if you
| have easy access to IJ/ij: U+0132 LATIN
| CAPITAL LIGATURE IJ U+0133 LATIN SMALL LIGATURE
| IJ
|
| (On the EurKEY layout[1] this is as easy as AltGr + k)
|
| [1]: https://eurkey.steffen.bruentjen.eu/
| corytheboyd wrote:
| I'm glad I'm not the only one who feels weird about shadowing
| existing executable names. It's actually fun to find commands
| I have never used before this way and read about them... then
| move on picking a different alias name. My dumb rule is
| anything I would have made a one letter alias, just use that
| same letter three times (ex: ggg=lazydocker)
| BeetleB wrote:
| > I think I need to come across some killer thing `z` does that
| I suddenly can't live without to overcome the activation
| energy.
|
| See my other comment on combining z and fzf:
| https://news.ycombinator.com/item?id=39030391
| dinkleberg wrote:
| If you're using oh-my-zsh you can add z to your plugins list and
| you'll get the functionality without needing to install anything.
|
| It is a must have
| wakeupcall wrote:
| zsh's has "cdr" as part of the standard distribution, which I
| have been using for years. See zshcontrib.
|
| I wonder if anyone can make a comparison. From an usage
| perspective, they seem equivalent. cdr's configuration is more
| zsh-like.
| whirlwin wrote:
| Anyone who have used both z and autojump? What is the difference?
|
| https://github.com/wting/autojump
| jdwyah wrote:
| autojump is first on my list of command line things I can't
| live without.
| linhns wrote:
| autojump allows you to open file manager, ... while z is truly
| "autojump", just cd into the directory.
| tkellogg wrote:
| FYI for windows, I made this a long time ago:
|
| https://github.com/tkellogg/Jump-Location
|
| Which was fun and all, but eventually replaced by a pure
| PowerShell implementation that's become far more active:
|
| https://github.com/vors/ZLocation
| pprotas wrote:
| I use this Rust clone which works great, no complaints:
| https://github.com/ajeetdsouza/zoxide
|
| Although, I don't know what the difference is, other than the
| language of choice.
| chadcatlett wrote:
| I used to use z, then z from omz but eventually switched fo
| zoxide because it also works on PowerShell.
| bshacklett wrote:
| It seems like the Rust community is quite happy to support
| alternative shells. I've seen couple of projects, now, that
| support way more esoteric shells than I would expect, like
| 'xonsh'. Starship (https://starship.rs/) immediately comes to
| mind.
| LatticeAnimal wrote:
| Zoxide's zi command does an interactive z. It is one of my
| favorite commands
| chris_st wrote:
| Thanks for this! I had no idea zoxide has this! Made my day.
| pohl wrote:
| The README is an order of magnitude more useful. The man page
| aesthetic of z's README hits me in the feels, but I prefer the
| better documentation of zoxide.
| Barrin92 wrote:
| biggest difference is probably that it works on Windows, which
| is something that I really appreciate about most of the Rust
| clones. Almost all of them are pretty platform agnostic.
| 7839284023 wrote:
| I like to use Z as a fish shell plugin. [1]
|
| > A pure-fish port means z is fast and fish-friendly, with tab-
| completions and lazy-loading. Top that off with great
| customizability and a small amount of added functionality.
|
| [1] https://github.com/jethrokuan/z
| ar_lan wrote:
| This is what I use. I am tempted by zoxide but I've never been
| unhappy with this, so the temptation remains quite low.
| tambourine_man wrote:
| I've been using for years, can recomend.
| mehdix wrote:
| Z is part of my dotfiles. Everywhere I clone them, Z would be
| available immediately.
| coopykins wrote:
| This looks great, I love finding simple productivity boosts like
| this. Not simple in implementation but simple in how easily it
| becomes part of your workflow.
| riddley wrote:
| Why is this better than CDPATH that is already built into my
| shell?
| keerthiko wrote:
| for one, it is not built into either of my shells: Windows
| gitbash, or OSX terminal.
| semanticist wrote:
| OS X Terminal isn't your shell, by default zsh is your shell
| on Mac OS, and it does support cdpath:
| https://zsh.sourceforge.io/Intro/intro_13.html
|
| I assume Windows Linux thing uses Bash? It works even more
| simply, exactly like $PATH.
| BeetleB wrote:
| Think of this as an auto-CDPATH. With CDPATH you have to
| explicitly add the directories. And even with CDPATH, it won't
| work if you need to go deep down.
|
| As an example, say I have
| ~/Programs/Firefox/Profiles/kdskdj/Cache.
|
| Most people would put just ~/Programs or ~/Programs/Firefox
| into CDPATH. If you want to get to the Cache directory, you
| still need to know "Profiles/kdskdj/Cache". With z, if you're
| lucky, you'll just do "z Cache". Worst case, "z Fire Cache"
| latexr wrote:
| I tried this and a handful of alternatives a while back, but
| would often get frustrated because they'd jump to something
| different than what I intended or were missing some directory I
| wanted.
|
| Eventually I came up with an alternative using fd1 and fzf2. I
| have a variant of this in my .zshrc: function n {
| cd "$(fd . "${HOME}" --type d --color never | fzf --select-1
| --query "${*}")" ls }
|
| Call it with `n` and get an interactive fuzzy search for your
| directories. If you do `n <argument>`, it'll start the find with
| `<argument>` already filled in (and if there's only one match,
| jump to it directly). The `ls` is optional but I find that I like
| having the contents visible as soon as I change directories.
|
| In my personal setup I'm also including iCloud Drive while
| excluding the rest of the Library directory3 as that is too
| noisy. I have a separate `nl` function which searches just inside
| `~/Library` for when I need it, as well as other specialised
| `n<char>` functions that search inside specific places that I use
| frequently.
|
| 1 https://github.com/sharkdp/fd
|
| 2 https://github.com/junegunn/fzf
|
| 3 Change the fd command to: fd . "${HOME}"
| "${HOME}/Library/Mobile Documents/com~apple~CloudDocs" --exclude
| '/Library/' --type d --color never
| techwizrd wrote:
| I was frustrated with jumping to frecent directories, so I
| "reverted" back to jumping back to bookmarked directories [0]
| (which I find much more predictable).
|
| 0: https://github.com/techwizrd/fishmarks
| BeetleB wrote:
| Yes, I made a similar keybinding for xonsh, using fd and fzf. I
| press Alt-c, and fzf shows me all the subdirectories rooted
| where I'm at.
|
| That's a good intermediary solution. But the one that totally
| changed my flow was to combine autojump[1] and fzf. autojump is
| similar to Z (this submission). It stores all the directories
| you've visited in an SQLite DB and can show them to you
| (ordered by visit frequency) with a command line argument. So I
| pipe that to fzf.
|
| Now I can _extremely_ quickly jump to any directory I 've been
| to before - it really helps that they're sorted by visit
| frequency. I honestly use this more than any other approach -
| and I probably go for days on end without using the usual TAB
| autocompletion.
|
| [1] https://github.com/wting/autojump
| mixedmath wrote:
| This seems pretty great! I love tips like this.
|
| I'm going to try out a version of this now.
| Arcuru wrote:
| In most shells, you can just add those entries as shell
| completions to `cd` or `z`.
|
| In fish for example, it's as easy as the following (using
| zoxide query) complete -c z -f -k -a "(zoxide
| query -l)"
| latexr wrote:
| I don't just want specific directories to autocomplete.
| Whatever I navigate to is likely something I never even
| opened but was generated by a script and I now want to do
| manual changes to the contents. This approach makes for me
| the rare case as usable as the common one.
| wingerlang wrote:
| My lowtech solution was to make a function with an array of
| hardcoded paths, it would then present a menu where you could
| select 0-N and it would jump. It also started with Terminal.
| twic wrote:
| My lowtech solution was just a bunch of aliases for directories
| i use a lot. Like: alias .a='cd
| ~/src/autosqueezer' alias .g='cd ~/src/gcc-squeeze-
| plugin' alias .u='cd ~/src/squeeze-utils'
|
| etc. You have to manage them by hand, but that's easy, and
| makes the result much more predictable than anything based on
| history.
|
| I also have contextual companions to these, defined as
| functions, like: .r() { local
| project_root=$(somehow work out the root of the current
| project) cd $project_root } .b() {
| .r cd build }
| cunningfatalist wrote:
| I have been using z for many years now, and I cannot recommend it
| enough. This is one of the most useful tools ever.
| soissons wrote:
| I used something different, but it didn't work as expected
| because I have multiple directories that start with the same
| letter. Consequently, the shortcuts changed their paths and I
| never ended up where I wanted.
|
| I built my own tool called Zee, that takes a simplified approach
| by only utilizing explicit user-defined shortcuts:
| https://github.com/dnsv/zee
| aperum wrote:
| I've been using enhancd for years now.
|
| https://github.com/babarot/enhancd
| linhns wrote:
| Honestly with fzf you can achieve the same thing. I'm not
| having anything against enhancd, but it's surplus nowadays.
| StanAngeloff wrote:
| Heavy user of `z` for many years... that is until it corrupted
| its own database one final time. There's nothing more frustrating
| than a dropped or corrupted directory database just as you've got
| the damn thing to remember all your favourite spots on the disk.
|
| These days I use https://github.com/gsamokovarov/jump which I've
| mapped to `z`. Happy days.
| patja wrote:
| Is there history or a meme that holds that z is for jump?
|
| Just wondering if that is why the hotkey for the jump action in
| Baldur's Gate 3 is z
| tkcranny wrote:
| Speaking with no actual knowledge on Z's naming, there is a
| long history and important relationship in CPU design between
| the "Zero flag" (Z), and "jump" instructions.
|
| The zero flag stores a status from the last instruction the cpu
| ran, which the jump cpu instructions then reference to affect
| what happens to code execution. This logic is the most basic
| form of conditionals, and underpins the implementations of
| higher level flow control like if statements and loops.
|
| I'd guess that this relationship between Z and jumping is where
| it comes from. As for Baulders Gate I have no idea, but lean to
| that being a coincidence.
| kazinator wrote:
| I've experimented in this area. I once made a "pcd" (parent cd).
| The idea is that "cd" (if relative) changes the last component of
| your directory: if you're in foo/bar and type "cd baz/xyzzy",
| then the /bar component is rewritten to /baz/xyzzy".
|
| My "pcd" would similarly rewrite the parent component instead. If
| you're in "a/b/c" and do "pcd x" you change to "a/x/c"; and "pcd
| x/y" would change to "a/x/y/c". Useful for when you have some
| similar directories with parallel structures.
|
| I gave it a numeric argument defaulting to 1. "pcd 0" is like cd,
| "pcd 1" is like pcd, and then higher integer switch higher
| components.
___________________________________________________________________
(page generated 2024-01-17 23:00 UTC)