| ▲ | robenkleene 3 days ago |
| How 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. |
|
| ▲ | nickjj 3 days ago | parent | next [-] |
| I like using fzf combined with zsh's shell history filtering. You can type `cd ~` and press CTRL+r to immediately fuzzy match commands you've run with `cd ~`. fzf naturally ranks paths to cd into on top. If you find that too noisy you can just hit CTRL+r with an empty prompt and then search for `^cd ~` to only find cd commands. I've written about filtering related history with zsh here: https://nickjanetakis.com/blog/hooking-up-fzf-with-zsh-tab-c... If you want to go into ultra lazy mode you can also type `cd ` and spam the up / down arrows to only show commands from your history where you cd'd into a directory. That use case is also covered in the above post. I normally don't use this for changing directories but it can be done. |
| |
| ▲ | jvanderbot 3 days ago | parent | next [-] | | You don't even need history. Just `find . -type d | fzf` to determine what dir to change to (or ~ for "anywhere else") 1. Make an alias fcd
2. Make a tab complete that does that for the command fcd This is kind of 101 bash - just DIY. Here's mine: (2) is the hardest part - just write something that works with `complete` and fzf. Nowadays this is childs play for any AI to just spit out. fz_comp()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local opts="none"
if [ -z "$cur" ];then
COMPREPLY=($(find $1 -type d | fzf --preview="ls {} -l"))
return
fi
COMPREPLY=($(find $1 -type d | grep $cur | fzf --preview="ls {} -l"))
}
(1) is just a) set the new command b) make the completion call c) map that call to <TAB> completion. alias fcd=cd
_fcd(){ fz_comp $(pwd) }
complete -F _fcd fcd
there you go. | | |
| ▲ | BeetleB 3 days ago | parent [-] | | If I'm reading this correctly, this will pass all subdirectories to fzf, which is very different from only directories you've visited. | | |
| ▲ | jvanderbot 3 days ago | parent [-] | | The premise is the same: Dump history into fzf and add a grep/awk. My point was that requiring a new shell (or even history) is a limiting factor here, and either backwards search over commands (as suggested ITT), or just plan fzf directory changes are more functional and already integrated into bash. | | |
| ▲ | robenkleene 3 days ago | parent [-] | | `cd foo` is useless in history if you're not already in foo's parent directory. This is the problem Zoxide solves, `z foo` will still do something useful in that case. (Side note about fzf, recursively fuzzy finding subdirectories fine for some use cases, but it doesn't scale as well as Zoxide.) | | |
| ▲ | jvanderbot 3 days ago | parent [-] | | Yes, the marginal improvements from changing your entire shell are not to be disregarded. I'll change to asserting that it's entirely possible to do a nice 80/20 without changing shells. | | |
| ▲ | robenkleene 3 days ago | parent [-] | | What do you mean? Zoxide isn't a shell, it's just a CLI program. It doesn't involve changing shells, you can see the list of supported shells in the README (it's more comparable to fzf than a shell, it ships with optional shell integrations the same way fzf does). | | |
| ▲ | jvanderbot 3 days ago | parent [-] | | How did you get all the way down here and lose the fact that top level comment is about zsh and finding past commands, and also changing directories? Was it not you that brought up zsh? And I that brought up bash examples to show how it might be done? We've gone around in circles lads back on the bus. | | |
| ▲ | robenkleene 3 days ago | parent | next [-] | | To me, the interesting conversation here is between these three workflows: 1. Recursive directory fuzzy-search 2. Searching history for `cd` commands 3. Zoxide-style matching visited directories Which are all ways to make it easier to traverse directories. For my part, the thrust of your argument seemed to be advocating for #1, so that's what I was responding to (since this is a thread on #3, I'm mainly focusing on why you'd use that instead of #1 or #2, but all three are workable). All of these can be implemented in any of the common shells. I didn't see anyone making a case for a specific shell here, I think the mentions of a specific shell are incidental (e.g., what people happen to use). | | |
| ▲ | BeetleB 2 days ago | parent [-] | | Indeed - it's not even an either/or. I have both 1 and 3 as keybindings. |
| |
| ▲ | BeetleB 3 days ago | parent | prev [-] | | He never said he changed shells - just that he uses zsh history. He was likely using zsh anyway. | | |
| ▲ | jvanderbot 3 days ago | parent [-] | | My logic (take it or leave it) is that since zsh is not the default distro nearly anywhere (Kali?), a randomly selected person who might read that advice (and subsequent advice ITT), would likely find "Use ZSH" includes a shell change and therefore more learning curve than "add a few lines to .bashrc". This is getting off topic, pedantic, and (maybe?) argumentative so I'm calling it quits. Cheers. | | |
| ▲ | BeetleB 3 days ago | parent [-] | | I believe the default shell in MacOS is zsh, not bash. So lots of folks use zsh by default. |
|
|
|
|
|
|
|
|
| |
| ▲ | BeetleB 3 days ago | parent | prev | next [-] | | It's (likely) simpler with zoxide + fzf. I use autojump, which is a lot like zoxide (possible predates it). It stores all the directories you've visited in an SQLite DB (along with the rank for each). I wrote a shell keybinding that presents me with fzf, along with the directories I've visited, in rank order. With just a few keystrokes, I can visit any directory I've ever visited, really fast. It doesn't need to be the top ranking directory for my query. I can't live without it now. | |
| ▲ | robenkleene 3 days ago | parent | prev [-] | | Yeah the problem with this approach to me is populating the history with a bunch of cd to absolute paths to begin with, which is not something I'd do natural (I have many ways I'm navigating the file system), and definitely wouldn't do manually. Not having to populate that list is the advantage of zoxide. | | |
| ▲ | jvanderbot 3 days ago | parent | next [-] | | From 2024 when this was last posted:
It appears to me that these could all be just tab complete, fzf, or similar. Some are just plain old bash. The commands are written in rust, presumably because they're part of this warp shell advertised on readme? I used to use this https://github.com/jodavaho/smartcd 'scd journal' 'scd logs personal' Now I tab complete using fzf, but the above is what you want. Bash is Turing complete. You "need" nothing else. You may want it for various reasons. | | |
| ▲ | robenkleene 3 days ago | parent [-] | | - Recursive directory tab completion isn't viable for many key use cases (it'll hang with both monorepos and networked volumes). The only thing that makes zoxide viable is that it only matches against visited directories. (Similarly fzf doesn't have much of a relation here besides encouraging recursive fuzzy matching, which I tend to avoid because it doesn't scale to complex directory structures.) - Zoxide is probably sponsored by Warp, I doubt they have a relation beyond that, I'm not sure but they don't have much of a synergy beyond both being written in Rust. (The main point of relevance here is Warp is venture funded.) - Zoxide having a database outside of the shell is actually a huge advantage to me, because it makes it easy to access your database outside of the shell (e.g., Zoxide integration in Vim). |
| |
| ▲ | nickjj 3 days ago | parent | prev [-] | | I think that's ok if you have absolute paths mixed in. If I have some long path like ~/src/open-source/dotfiles or /home/nick/src/open-source/dotfiles it all works with fuzzy matching. You can hit CTRL+r and then search for "cd dotfiles" and it finds it. The ~ isn't necessary, you can also do "^cd dotfiles"` for a tighter list of matches for paths that are more ambigious with other non-cd commands. |
|
|
|
| ▲ | Latty 3 days ago | parent | prev | next [-] |
| It'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 3 days ago | parent [-] | | The issue for me with this approach is one: It assumes a clear root for a project (e.g., your base you're cd-ing off of), I think that's only good assumption for small-scale projects? E.g., sufficient complexity, for programming at least, necessitates modularity which dilutes the concept of a "root". The other issue is that it creates a separate "hop" which adds key strokes and cognitive load (i.e., I can't just jump directly to a subdirectory or related directory I first have to jump to a "junction" directory then to my destination). In any event, I could see how that would be a reasonable approach in the absence zoxide, but those are the reasons I personally still prefer zoxide. (For the record, zoxide has some nice techniques for making a match more specific, e.g., `z foo bar` will hop to a dir containing `bar` only if it's in a subdirectory containing `foo`. | | |
| ▲ | AyyEye 3 days ago | parent [-] | | Mcfly[1] takes your working directory into account when searching shell history. From the readme: > The key feature of McFly is smart command prioritization powered by a small neural network that runs in real time. The goal is for the command you want to run to always be one of the top suggestions. > When suggesting a command, McFly takes into consideration: - The directory where you ran the command. You're likely to run that command in the same directory in the future. - What commands you typed before the command (e.g., the command's execution context). - How often you run the command. - When you last ran the command. - If you've selected the command in McFly before. - The command's historical exit status. You probably don't want to run old failed commands. [1] https://github.com/cantino/mcfly | | |
| ▲ | fragmede 3 days ago | parent | next [-] | | > The directory where you ran the command. I love that mode in Atuin. I can never remember which of the run commands to use between make/cmake/bazel/yarn/npm/uv and hitting ctrl-r twice and scrolling up is better than having to root around in a readme, which I may or may not have bothered to write for my future self. http://atuin.sh/ McFly sounds interesting! Added it to my list of things to investigate. Does it do multi-machine syncing? | | |
| ▲ | skydhash 3 days ago | parent [-] | | You can settle on make (or just) and have consistent targets like run, test, build, deploy, etc…. I use emacs, so I have compilation buffers for those. | | |
| ▲ | fragmede 3 days ago | parent [-] | | Oh I forgot about "just"! (and I have Opinions about that name.) Add that to the list. Making order from chaos is not unfamiliar to me. Previously I standardized on make and was fastidious about making makefiles, but with atuin, command directory history the extra effort to create makefiles became superfluous. I used to have this fantasy that after I die, someone will care enough to go through my ~/projects folder and go through everything I worked on, and all those makefiles and readmes were going to help them, but no one cares that much for me. I'm okay with that, depressing as it is. |
|
| |
| ▲ | fragmede 3 days ago | parent | prev [-] | | > The command's historical exit status. You probably don't want to run old failed commands. Yeah but the other commands I ran is so that one succeeds. |
|
|
|
|
| ▲ | alright2565 3 days ago | parent | prev [-] |
| There's no need to type "cd", just the folder name and hit up until you get to the right command. |
| |
| ▲ | robenkleene 3 days ago | parent [-] | | That'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. |
|