5 ms·
I tried zoxide for a while but I really disliked how it made things fuzzy, and most of the use cases for it I found were 90% solved by using ZSH's history searc
by Latty 1y ago
I tried zoxide for a while but I really disliked how it made things fuzzy, and most of the use cases for it I found were 90% solved by using ZSH's history search which I use routinely anyway.
It gives you this potentially constantly shifting set of shortcuts, essentially, and the problem is that means I have to constantly check I did get the result I wanted, and that I haven't accidentally gone to the wrong place. I found that more annoying to me than just using tab completions or history, which are much more predictable.
I can see how someone who has different workflows or environments might find it great though.
- mrcarrot 1y agoYeah, I've been trying it recently and I'm not entirely convinced I want to keep using it. My biggest annoyance at the moment (and this may be me missing something), is that I have two directories: "thing" and "thing-api". I'm doing work in "thing" much more often than in the "thing-api", but whenever I run "z thing", it takes me to "thing-api" first, and I have to "z thing" again to get to where I wanted to go. It ends up being more effort than if I'd just tab-completed or history searched a plain cd command.
- paholg 1y agozoxide stores a rank for each directory based on how often you visit it, but you can manually adjust the scores. Run `zoxide query -ls thing` to see the scores, and `zoxide add thing -s AMOUNT` to increase the score.
- yonatan8070 1y agoThat's good to know, when I needed to raise the score for a directory I just did a bunch of `cd .`
- neobrain 1y agoPerhaps helpful: There's also a `zi` command, which prompts you with a list of all matches before changing directories. Personally there's only few directories where I need it, and I just memorize using zi instead of z for those. However I agree z should ideally have some syntax like `thing$` to denote a full directory name instead.
- dicytea 1y agoYeah I aliased zi to z for this reason. z feels too much like a lottery ticket.
- keybits 1y agoThe aha moment for me was to type a space after the characters I'm searching for - then hit tab. You then get the list of options ranked (and a nice view showing the contents of each folder).
- cycomanic 1y ago> Yeah, I've been trying it recently and I'm not entirely convinced I want to keep using it. > My biggest annoyance at the moment (and this may be me missing something), is that I have two directories: "thing" and "thing-api". I'm doing work in "thing" much more often than in the "thing-api", but whenever I run "z thing", it takes me to "thing-api" first, and I have to "z thing" again to get to where I wanted to go. It ends up being more effort than if I'd just tab-completed or history searched a plain cd command. AFAIK the z command does take frequency into account (or was it most recent visit). However to avoid going into thing-api instead of thing I believe you just type thing/ i.e. At the slash and z will take you to thing (that obviously doesn't work with tab completion though). I found that after some time I have gotten so used to z (which I aliases to cd) that I wouldn't want to live without it.
- BeetleB 1y agoI wrote a shell keybinding that presents me with the candidates using fzf (in rank order). This way I can see which one it will go to and pick the "correct" one if need be. It's blazing fast.
- yonatan8070 1y agoI generally work in only a few folders (we'll call them project a, project b, project c), so once I taught it these are high priority, it just works when I type any part of their names
- Perz1val 1y agoSame and I'm about to try the counter approach: just alias those few things
- cb321 1y agoIn Zsh with `setopt autocd cdablevars`, shell variables more or less work like cd-aliases. You could also just add `a=projectA; b=projectB; c=projectC` to your `~/.zprofile` and then at prompts type 1-letter commands `a`, `b`, `c`. One added bonus of such file tree bookmarks via variables (over a similar `alias a='cd foo'`) is that if you get muscle-memory/active memory for those few abbreviations other use cases like `make -C $a` also work. I usually leave `$hb` & `$lb` set to `$HOME/bin` and `/usr/local/bin`, for example.
- darkamaul 1y agoThe comment above is something I love about HN. I never knew this existed and would not have even thought to search for it but, but that’s something that I see me using everyday.
- cb321 1y agoGlad to be appreciated. You might also enjoy this snippet from my zshrc: my-expand() BUFFER=${(e)BUFFER} CURSOR=$#BUFFER zle -N my-expand # Make Alt-E expand environ vars w/o val escape bindkey '^[e' my-expand # Allows eVar "short cuts" for history !!:gs etc It's vaguely related in that it lets you put a variable in the main Zsh Line Editor (ZLE) buffer (with the leading `$`) and then press Alt-E to expand it. ('e' for E)nvironment-E)xpand). As per the comment I did this so that I could have "history substitution expressions" stored in variables, then Alt-E - look (& maybe edit) & ENTER. The history syntax itself is very cryptic, derived from early 1980s BSD csh. As with most such crypticnesses, figuring it out once, storing it somewhere you can remember, and expanding it on demand is a not awful way to learn it. But besides cryptic history directives you could also use it for the `$a<Alt-E>` above to "see before you do". You need an extra `$`, though, as written. It would be pretty easy to auto-add a `$` prefix in `my-expand`, though (with Alt-E just becoming a sort of different kind of TAB for expansion rather than completion).
- sandreas 1y agoI use fzf completitions source <(fzf --zsh) > /dev/null and the ** shortcut followed by <TAB>, e.g. cd ~/** # <TAB> along with cd - to change to the directory before cd -
- robenkleene 1y agoThis will hang if you have too many subdirectories (e.g., a good-sized company's monorepo). A networked volumes will also often cause it to hang. (PS: In Zsh `cd -<tab>` will show a pop up menu of all directories in the history stack.)
- sandreas 1y agoSeems to be some kind of oh-my-zsh thing... cd - <TAB> does not work on my zsh config.
- robenkleene 1y agoAh, good point, this isn’t `oh-my-zsh` but it does require a couple of options to work as described: 1. `setopt autopushd pushdsilent`: This is the key component, `autopushd` automatically adds directories to the directory stack (and `pushdsilent` option does it without echoing added directories). Without this option, there’s no directory stack to traverse (unless directories are first manually added to it with `pushd` [for completion, `popd` pops directories off the stack navigating back to those directories]). `autopushd` just calls `pushd` on the current directory after each `cd`. 2. To get a menu, Zsh completion also has to be loaded, e.g., `autoload -Uz compinit && compinit -C` 3. Finally `zstyle ':completion:*' menu select` is optional, but that highlights the selected match, which is a nicer UI in my opinion. Those are the options I used to get this working with `zsh -f` (which starts Zsh with a default config).
- sandreas 1y agoWorks, is really nice, thank you. May I (auto-)suggest: https://github.com/zsh-users/zsh-autosuggestions https://github.com/zsh-users/zsh-autosuggestions Have fun ;-)
- eviks 1y agoYou're right, "z d" to always to always go to your downloads folder if way more powerful than whatever fuzzy match can achieve, and unfortunately the project didn't want to add a predictable input mechanism, though maybe that'll change in the future...
- robenkleene 1y agoHow are you using Zsh history to navigate to specific folders? E.g., does that mean you always start your `cd` from the home directory (e.g., `~`)? I'm asking because it's usually less key strokes to `cd` to a relative directory (assuming you're working in several related directories). But then the `cd` entry in your history would assume a specific starting path (and therefore wouldn't be universally helpful to recall from history)? Also, re: > the problem is that means I have to constantly check I did get the result I wanted, and that I haven't accidentally gone to the wrong place. Is there a reason you don't add your current path to your prompt? I don't know how I'd work without that, never knowing which directory I'm in.
- alright2565 1y agoThere's no need to type "cd", just the folder name and hit up until you get to the right command.
- robenkleene 1y agoThat's not default behavior in most shells (e.g., `autocd` in Zsh, and, for the record, that's also not default up arrow behavior in Bash or Zsh [it is in Fish]). But my question is specifically about relative vs. absolute paths when recalling directory traversal from history. I'm still struggling to follow how you'd use Zsh history as a zoxide replacement without always using absolute paths.
- Latty 1y agoIt's not that I always use absolute/home-relative paths, but I'm almost always working from the same folders for the context: if I'm working on a project, I'll be in the project directory and work relative to that the vast majority of the time, for example. I also use the substring history search which makes it more useful for the equivalent to zoxide's case. And I do have my path in my prompt, I'm not talking about something that actually takes time, but more interrupts flow (for me, as I say, I get how for other people it'd work better).
- robenkleene 1y ago