1. 38
  1.  

  2. 11

    Nice section titles!

    If you haven’t tried it already, you might want to look into fish shell or zsh autosuggestions. The idea is to automatically show the top entry from history, which matches current command.

    I subjectively like this UX a lot: nothing to configure, nothing to invoke explicitly, surprisingly broad applicability (cd is just one command which benefits from this). In other words, just like how dev tools should work (:

    1. 3

      Thanks!

      Good advice about zsh and autosuggestions. I am using bash so have no niceties like that, but others will definitely find it useful. Personally, at the current stage, I consider my problems with filesystem navigation to be more or less solved, using the simple folder structure described at the end.

      1. 3

        Yes! Fish is a great suggestion. I will add that both Zsh and Fish support autocompleting long paths by typing something like ls ~/w/b/p/tand then hitting tab, so that it autocompletes to ls ~/work/bitbucket/project/tests or whatever. If there’s any ambiguity, you can add more characters or keep pressing tab until the right path shows up. Combine this with the suggestions and control+E in Fish and I’ve been a lot more productive.

        1. 1

          I will add that both Zsh and Fish support autocompleting long paths

          TIL, thanks!

      2. 10

        I frankly got used to ls+cd+find.

        But then, I just might be a mad man.

        1. 8

          In addition to cd and ls, I suggest to use pushd/popd. Built into practically every shell, so nothing to install.

          Apart from that, Fish autocompletion is good enough to remember my “current” project folders.

          1. 2

            Is there a way to automatically push a directory unto the directory stack? And possibly just have it remember the last 10, 20 or however much? pushd/popd are two commands I could never get used to, because I think of them after I need them, not before.

            1. 5

              I think using popd after pushd is seldom useful.

              What I do is prepopulate the dirs stack using pushd -n and then navigate between the “bookmarks” using tilde expansions like cd ~2 which don’t “pop” folders from the stack.

              1. 1

                I think using popd after pushd is seldom useful.

                Why? It would be like a “back” button in a browser/file manager.

                navigate between the “bookmarks” using tilde expansions like cd ~2

                Meh, I have a “jump” function already where I can use human-readable names.

              2. 2

                Unfortunately bash doesn’t have zsh’s autopushd. Years ago I made two aliases that suppress pushd/popd’s noisy output and alias cd/bd (“back directory”) to them - I’ve found it very handy and use it daily.

                # don't echo the current stack on pushd
                function quiet_pushd() {
                    # preserves functionality when aliasing cd to quiet_pushd
                    if [ $# == 0 ]; then
                        builtin pushd $HOME/ > /dev/null;
                    else
                        builtin pushd "$@" > /dev/null;
                    fi
                }
                
                # don't echo the current stack on popd
                function quiet_popd() {
                    builtin popd "$@" > /dev/null;
                }
                
                1. 1

                  In zsh: setopt autopushd

                  I’m unclear about other shells, though it can be emulated by writing a function / alias for cd.

                2. 1

                  I know about pushd and popd, have a few scenarios in my head where I think they might be useful, but have never used them productively in practice. Some times I note in passing that it would be nice to go back more levels into cd history than simple cd - but those moments are quite rare. And once you catch yourself wanting to do that using pushd is already too late.

                  I secretly wish pushd would be auto implemented as cd history with a shortcut to trigger it, like maybe cd ^

                  1. 2

                    autopushd and pushdsilent seems to be what you want. I think oh-my-zsh enables them by default but I’m in the process of setting my shell from scratch these days (zsh + starship + cherry-picking the cool parts of oh-my-zsh) for performance reasons, and this discussion finally made me search for it.

                    http://zsh.sourceforge.net/Intro/intro_6.html

                    1. 1

                      Thanks for these.

                      I am somewhat on a streak for getting back to minimal (almost ascetic) setup on my machines, so things like zsh are out of the question. But will definitely keep autopushd thing in mind if someday I change my mind.

                3. 5
                  1. 4

                    I also just got rid of the idea of bookmarks. I just search history with ctrl+r.

                    1. 2

                      In the same vein: I very often use absolute paths with cd so that I can use my command history from anywhere. I find it very useful.

                    2. 3

                      Great read. I couldn’t adopt this folder structure though. I’m too wedded to having year folders (2020,2019 etc) at the roots.

                      1. 3

                        Erm… honestly, I’ve just used screen or tmux for the past many years, and combined that with not turning off computers (just sleeping or hibernating them). As such, cd and friends have been enough for me.

                        1. 3

                          A while back I moved from z to fasd. That plus fzf makes for some nice navigation and completion.

                          1. 1

                            Any reason why you moved? I’m looking for a pure POSIX alternative to z (supports only zsh and bash AFAIK), and fasd seems to be it.

                          2. 1

                            I’m partial to my take on z:

                            $ j llvm-9
                            

                            Expands to:

                            $ cd ~/Projects/llvm-9
                            

                            Because it’s a direct mapping, there is no configuration to do. There’s no learning period. It is easy to setup auto completion and I’m awful at shell scripts. Also, it is 8 lines long in zsh!

                            For two level project dirs, I’d probably just copy paste the j definition and name it zzz or something similar after tweaking the paths.

                            Link

                            1. 1

                              In my experience the fastest way to navigate is a combination of fish completions and nnn. I even have a static binary of nnn that I use for remote machines.

                              1. 1

                                I’ve solved my need for fast navigation with my own tool named “wd” (on github).

                                If your brain works better with numbers than with “human-readable” mnemonics then give it a try. For example, wds2 will save the current directory into $WD2, and you can jump back to it with wd2. Slot zero is even shorter with just wd.

                                It supports named schemes with autocompletion, so you can make one for each “project” context.

                                1. 1

                                  One additional solution, which I find very practical: cd work///the-specific-repo works, exactly if the path expands to one directory (i.e. if the-specific-repo is unique.)

                                  1. 2

                                    Argh, this was meant to be cd work/*/*/the-specific-repo.