Live data from Hacker News

How to navigate directories faster with Bash (2015)

mhoffman.github.io

171–179 of 179 posts

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

#172
post #166

Earlier quoted context omitted.

Similar is https://lib.rs/crates/zoxide if you're a fan of rust based solutions :) .

I don't think zoxide keeps an eye on shell history or uses a shell hook to see which dirs you navigate to manually? It seems it collects history only through its own CLI?

You're wrong it watches what you do and where you go via the shell command history file.

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

#173
post #14
post #6

Good selection of tips, like Normille I didn't know $! even though I have read Bash's man page through more than once. Note that many of these are not just for Bash. pushd/popd is near universal among shells and CDPATH is standard among SYSV shells. The idea of a shortcut for cd .. and its repetitions is good, but I'd prefer alias p='cd ..', pp='cd ../..' and so on, since I balk at the idea of having to distinguish,…

I'm an old-timer so was introduced to Unix before bash was ubiquitous. Actually it was csh/tcsh which later introduced me to "interactive" command history/editing. With interactive command history/editing, the old tricks to avoid excessive typing became less essential. But I still use some of the old techniques as they continue to save time/typing - particular "$!". And even though I've reduced my reliance on aliases…

> I'm an old-timer so was introduced to Unix before bash was ubiquitous.

Me too, my first contact with UNIX was with SunOS 4 in 1988, which had csh as its default shell. I don't think I switched to bash until I started administering a Linux box in 1999, although I did script in POSIX shells before then. Before I had a system I was in control of, my attitude to bash was that it was unportable, because of the major differences between its v1 and v2 syntax.

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

#176
post #155

Here is one additional bookmark solution [1]: export CDPATH=.:~/.marks/ function mark { ln -sr "$(pwd)" ~/.marks/"$1" } mark @name # create a bookmark cd @name # jump to bookmark cd @ # list bookmarks cd @n # auto-complete cd @name/ # can access sub-directories within bookmarks Works best when bookmarks are prefixed by "@" or other special symbol. Additional advantage is that you can use the same function `cd` to nav…

Might be worth pointing out the author of the post you linked settled in the end on `cd` and `ls` in a different style of organization over bookmarks or `z` or any other tool.

[deleted]

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

#177
post #104

No mentions of https://github.com/jarun/nnn yet? I've really taken a shine to using a real file manager with lots of nifty features without any bloat.

Yes, nnn is completely navigation oriented with an extra focus on speed and remaining lightweight. The plugin autojump supports jump/autojump/zoxide.

Great job on nnn! I feel like I've only scratched the surface of what it can do but I still use it many times per day.

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

#178
post #82

Would it possible to alias the escape codes make by the up arrow as 'cd ..'

It is possible. Just source that. bind '"\e[A":"cd ..\n"' But would you really want that rather showing previous command?

Cool, and duh about the previous command. I supposed some key that's not used for anything on the command line would be needed. Keypad up arrow instead of regular up arrow. Or a single ESC?

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

#179

Not a word about command editing. Learn keyboard shortcuts to edit the current command line and you'll save years of your life. ESC-. (dot) will get the last argument of the last command. This one alone will save you months. CTRL-R will search backwards. This other will save more months.

I remember being advised that it was more efficient to use the command line editing shortcuts instead of changing directory. That was over 10 years ago and I still use the shell with this in mind. I’m not saying I never change directory, but once I do, I tend to stay there. I had to scroll a fair way down to find a comment validating this opinion. Perhaps we’re wrong when saying to change directory efficiently, you d…

Much faster. Using absolute (or home-relative ~) paths save a lot of time. Because now you can reuse commands a lot more and CTRL-R will yield more hits.
Post reply on HN