Live data from Hacker News

How to navigate directories faster with Bash (2015)

mhoffman.github.io

131–140 of 179 posts

Re: How to navigate directories faster with Bash (2015)

#131
post #2

I upvoted for this alone: Another neat short hand is !$ which is an alias for the last argument of the previous command. This can be handy if one creates a new directory and wants to change into it without typing the the directory again. So commands would be mkdir -p make/new/directory cd !$ You've no idea how many years I've been thinking "This is Linux fer gawd's sake. Surely there must be some easy way to make a n…

I know this is a bash thread but zsh/oh-my-zsh will replace !$ with the actual argument when you type a space so you can see and edit it before executing the command.

Re: How to navigate directories faster with Bash (2015)

#132
post #100

Or you just use a shell like fish that already comes with a lot of useful defaults. No need to customize everything by yourself, just use what other smart people already created. https://fishshell.com/

Yeah, to echo -- this probably works for people new to the whole thing, but like many here, it's easier to train myself incrementally with individual features added to bash than to try to "start over."

Re: How to navigate directories faster with Bash (2015)

#133
post #55

Earlier quoted context omitted.

[ESC + .] and [ALT + .] are most definitely news ones for me. Thank you. Always learn something new here!

https://www.gnu.org/software/bash/manual/html_node/Bindable-... is a must read.

Thanks, I discovered C-o thanks to you (even though I have gone through the bash manual several times).

No, more having to press C-r multiple times just to get sequential group of commands from history.

Re: How to navigate directories faster with Bash (2015)

#134
On a Mac, Findspot supports fuzzy directory search, either as a key sequence or via the command line (my alias is "c").

https://gumroad.com/l/findspot

I experiment with many forms of automation and stick with few of them. Interface complexity has a cost; there's a reason keyboards don't have more keys. For me, Findspot is indispensable.

Re: How to navigate directories faster with Bash (2015)

#135

The author missed to mention one of my favorite tricks to change back in to the last visited directory: cd - Hint: Change into directory called '-' can be done by cd ./- I also use the mkcd alias / function: mkcd() { mkdir -p "$@" && cd !$; } This allows creating multiple dirs and cd into the first one. mkcd test1 test2 test3

I don't think this is documented anywhere that I've found, but

   git checkout -
checks out the previous branch you were on, similar to cd -

Re: How to navigate directories faster with Bash (2015)

#136

Earlier quoted context omitted.

Beware that using "$@" there might not be what you want, as it passes space-separated arguments to mkdir. What does: "mkd foo bar" do? It creates both directories, and cd's into "bar". Might be worth checking that only one argument has been passed, or use "$*" which instead would treat all arguments as one parameter, and "mkd foo bar" would create a "foo bar" directory instead (and cd to it) YMMV.

All Bash manuals and tutorials should start from explaining this issue. And I really mean it. I can't remember how many times I was bitten by it until I finally read it up.

I feel one should also install shellcheck, and follow it religiously while looking up every warning they get - to understand what it's about, why it's a problem, and why the solution / "correct" incantation is so.

It's also a good way to "learn by doing", which works for many.

Re: How to navigate directories faster with Bash (2015)

#137
The most important tool I found for switching directories is called "z". You just partially type a previously visited directory's name and it takes you there. It also keeps track of your history to rank candidates for popularity. https://github.com/rupa/z/ It's basically CDPATH on stereoids and doesn't require preconfiguration like CDPATH.

Re: How to navigate directories faster with Bash (2015)

#138
I have been using this "magic cd" alias for a while. You just type c and then the name of a folder, and it will find the most commonly visited folder with that name from your history and send you to it. It also supports tab completion.

https://gist.github.com/iwalton3/3f9bfce510f959782404be25cab...

Re: How to navigate directories faster with Bash (2015)

#139
We tried to somewhat mimic the finder experience when implementing directory navigation at Fig (https://withfig.com). Except of course, we make it all keyboard driven!

The methods listed in the article are almost certainly better if you know exactly which directory you need to go to (like a specific project repo, your bin etc) however often you don’t!

Another interesting tool is Z: https://github.com/rupa/z

Post reply on HN