Live data from Hacker News

How to navigate directories faster with Bash (2015)

mhoffman.github.io

101–110 of 179 posts

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

#101
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.

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

#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.

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

#105
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…

Also take a look at M-. (Meta+dot) which does the same thing while interactively editing a command...

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

#106
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…

In zsh, you use -> % take which makes the dir and cd's into it.

That isn't standard zsh behaviour. I suspect it comes from oh-my-zsh¹, but wouldn't be surprised if it isn't a bunch of the configuration bundles.

¹ https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/functions...

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

#109

https://github.com/junegunn/fzf also has a “cd mode”, by default triggerable using Alt-C, which can be useful.

In my opinion this replaces (and even does a much better job i.e. less typing in the end, less commands to remember) almost everything in the article, especially when combined with https://github.com/rupa/z/. (or the PS counterpart ZLocation). Might be the type of work of course, but ever since I started using this I can go by weeks without needing to manually type cd. After all most of my time is spent in the same directories anyway. And if not, I'm really not manually going to type it, not even tab it, if it can be fuzzy matched since that is nearly always faster. tldr; people do yourself a favor and stop cd'ing around.

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

#110
I do the following [1]:

- I define "cdn" to be what others call "mkcd", as then if I have a command line "cd foo" and it tells me that foo doesn't exist, I can just add the 'n' to the previous entry. I also overload "cdn" so that when not given any argument, it goes into the newest subdirectory in the current directory.

- "u", "uu", "uuu", "uuuu", "uuuuu" for going "up" that many levels, and unlike the aliases in OP, I define them as functions and if those are given an argument, they descends into the path from there: "u foo" is equivalent to "cd ../foo", "uu foo" to "cd ../../foo".

- I also have a function called "mvcd foo bar" that moves foo to bar and then goes into bar. "mvcdnewdir foo bar" that does the same but will create bar. (I'm pondering unifying them to a version that always calls mkdir -p)

- an alias "c" for cd [2]. The single letter messes with the history search though (ctl-r c space or ctl-r cd space ?), so it's not necessarily a good idea. `shopt -s autocd` that I just learned about here may be better.

- some functions for special locations, "cs" for ~/scratch, "cb" for ~/bookmarks, etc.

[1] see .bashrc at https://github.com/pflanze/chj-home [2] but I never use bash's "alias" since aside of being shorter it is always worse than a function (no way to extend it later to take parameters, and messes up live redefinitions)

Post reply on HN