after every cd

https://mas.to/@changoteca/115940445541109805

947 points · 56 comments · view on lemmy.world

56 Comments

wildbus8979@sh.itjust.works · 79 pts · 213d (19 replies)

Let me teach you about reverse-i-search in bash....

https://linuxvox.com/blog/ctrl-r-linux/

RollForInitiative@feddit.org · 42 pts · 213d (10 replies)

Yep, thats a good one. Another one, ALT + . inputs the last argument from your last command, pressing it multiple times cycles thorough your past arguments.

wildbus8979@sh.itjust.works · 18 pts · 213d (9 replies)

Nice, 30 years and I didn't know this one. I always use the $! for the last argument.

toynbee@lemmy.world · 8 pts · 213d (8 replies)

I've never heard of $! but we use Macs at work. Alt+. doesn't work so I've been using $_.

softwarist@programming.dev · 6 pts · 213d (7 replies)

⌥+. does the trick for me on MacOS.

toynbee@lemmy.world · 2 pts · 213d

Sorry, I should have been more clear ... When ssh'd into a remote Unix machine from a Mac, it doesn't me. I don't think I've tried locally.

Inkstainthebat@pawb.social · 2 pts · 213d (2 replies)

Wow, that's a new Unicode symbol

softwarist@programming.dev · 2 pts · 212d (1 reply)

You might have fun perusing the Miscellaneous Technical block (I sure did).

Inkstainthebat@pawb.social · 1 pts · 212d

Dentistry symbols???

toynbee@lemmy.world · 1 pts · 212d (2 replies)

Just as a matter of interest, I just tried this and it simply printed ≤ on the console. I'm using Terminal and Tahoe 26.2.

softwarist@programming.dev · 2 pts · 212d (1 reply)

I think for Terminal.app you have to enable "Use Option as Meta key"

toynbee@lemmy.world · 2 pts · 212d

I'll try to remember to check it out in the morning, thank you.

edit: This worked. This is amazing. Thank you so much.

ttyybb@lemmy.world · 11 pts · 213d

I don't even want to think about how much effort this has saved me.

ScientifficDoggo@lemmy.zip · 9 pts · 213d

Yeesh, I just learned something new. Thanks!

Syndication@lemmy.today · 4 pts · 213d (1 reply)

I was just about to ask how the hell anyone remembers or knows all these commands, thanks for the info! I am trying to learn Linux and get used to using the Terminal more often.

wildbus8979@sh.itjust.works · 3 pts · 213d

You can also just grep through your .bash_history

Aussieiuszko@aussie.zone · 2 pts · 213d

Neat

surewhynotlem@lemmy.world · 1 pts · 213d

Huh. And here I had aliased "history | grep" to hgrep and was using that.

Strider@lemmy.world · 1 pts · 212d

Also 'cd -' and aliases... 😁

pineapplelover@lemmy.dbzer0.com · 1 pts · 213d

And in fish

pinball_wizard@lemmy.zip · 34 pts · 213d

This thread is full of great solutions that I know I will ignore...

bdonvr@thelemmy.club · 26 pts · 213d

Ctrl-R

Try it. Please, I beg you.

Anafabula@discuss.tchncs.de · 16 pts · 213d (1 reply)

I also recommend Atuin, the better shell history that works with most shells and can replace both up arrow and ctrl-r

Wildmimic@anarchist.nexus · 2 pts · 213d

Thanks for that, thats much more comfortable!

ada@piefed.blahaj.zone · 15 pts · 213d (2 replies)

In addition to ctrl-r, there is also fish! Fish does something similar to Ctrl-R, but in an easier to use way. Start typing a command, and then press the up arrow. It will cycle through your history, but only the history that includes the text you've started typing.

Undearius@lemmy.ca · 11 pts · 213d (1 reply)

This can be enabled in bash by putting these two lines in ~/.inputrc

"\e[A": history-search-backward
"\e[B": history-search-forward
Wildmimic@anarchist.nexus · 2 pts · 213d

My Nobara installation has those commands mapped to pageup/down by default, so it's probably a default in other distros too if anyone wants to try it out without editing first

pedz@lemmy.ca · 13 pts · 213d (1 reply)

To be even more efficient while being lazy, try oh-my-bash. You can start typing the beginning of a command and use arrow up to cycle through only those, instead of the whole history. So if you had a very long mount command and don't want to type it again, type mount and up arrow until it can be found. Not very useful for ls -al but very appreciated on longer commands.

chellomere@lemmy.world · 8 pts · 213d

I personally use fzf to do basically the same thing, I just have to press ctrl-r before I start to type, and it does fuzzy matching to your history and shows more than one alternative at a time

AI_toothbrush@lemmy.zip · 11 pts · 213d (8 replies)

Very useful tip: i have ls aliased to eza which is ls with eyecandy, I have la aliased to eza -a and I have cd aliased to cd && eza which makes navigating folders very easy. I also aliased .. to cd .. for convenience. I know a lot of people are purists about the terminal but i think this is a good ballance between convenience and simplicity. Doesnt do a lot of the cursed stuff ricers like to do.

Anafabula@discuss.tchncs.de · 11 pts · 213d (1 reply)

cd is a zoxide alias for me. If I need to navigate by folder content, I have yazi on y

AI_toothbrush@lemmy.zip · 3 pts · 213d

Yazi is nice but when im navigating shorter directory structures i prefer cd. Question of personal preference as all of this is.

DaforLynx@lemmy.zip · 3 pts · 213d (1 reply)

Love convenient aliases. Would aliasing .. cause "../previous/file" to become " cd ../previous/file" and ruin some commands? I guess not. I also use eza :D

Prunebutt@slrpnk.net · 3 pts · 213d

Only if it's a global alias, I think (those are useful for stuff like alias -g DN=/dev/null)

Wildmimic@anarchist.nexus · 2 pts · 213d

ooooh that's nice! i love this threads, my shell gets soo much nicer! thank you all, you are great!

Inkstainthebat@pawb.social · 1 pts · 213d (2 replies)

How do you have cd && eza setup? With an alias the arguments only get appended to the final command so how is it cding to the correct folder?

AI_toothbrush@lemmy.zip · 2 pts · 213d (1 reply)

I think i defined cd as a function for interactive shells or something. I dont remember and i dont have my computer so yeah. It should look something like this: cd() {builtin cd "$@" && eza}

Inkstainthebat@pawb.social · 1 pts · 212d

yoink <3

lmmarsano@lemmynsfw.com · 10 pts · 213d

Reposted yet again.

As usual, the documentation covers these answers plus much more.

ramenshaman@lemmy.world · 10 pts · 213d

$ sudo apt install sl

Try sl instead of ls, you'll thank me later

jikt@sh.itjust.works · 9 pts · 213d

history | grep 'ls -la' | sed 's/^[[:space:]]*[0-9]\+[[:space:]]*//' | sh

irelephant@lemmy.dbzer0.com · 9 pts · 213d (1 reply)

cd - will bring you to the last directory you were in.

Electricd@lemmybefree.net · 2 pts · 213d

😮

Gyroplast@pawb.social · 7 pts · 213d (2 replies)

I like the retro text adventure charm of running a verbose ls -la after every cd. It's like entering a new room and reading its description for possible exits and items!

Aneb@lemmy.world · 4 pts · 213d

I aliased cd | ls -la to cd so it lists the folder contents eveytime

tracelr402@piefed.blahaj.zone · 2 pts · 213d

this is the sort of cozy thought I love to encounter on the internet

FauxLiving@lemmy.world · 7 pts · 213d

ls, ctrl+R

Significantly less up arrows

TheTechnician27@lemmy.world · 5 pts · 213d (1 reply)

I just alias ls -lah to lsl.

ratel@mander.xyz · 5 pts · 213d

Yeah lk = ls -larth for me because lk is right next to each other.

gandalf_der_12te@discuss.tchncs.de · 5 pts · 213d

ls -alh try that. -h means human-readable file sizes

Zink@programming.dev · 4 pts · 213d (1 reply)

I leave ls alone and instead do

alias l='ls -latrF'

I do sometimes just want to use the plain version, especially if I'm in a small terminal window for some reason. But I think my brain likes scanning 1D lists more than 2D grids, no matter whether I'm in a terminal or using a graphical file manager.

raspberriesareyummy@lemmy.world · 1 pts · 213d

Plain version is the one to pipe output for further processing. ls | wc -l

mudkip@lemdro.id · 3 pts · 211d (1 reply)

Pro tip, just do:

alias ls="ls -lah"

HoloPengin@lemmy.world · 2 pts · 209d

Alternatively, use a different alias so it doesn't override the original. "la" and just "l" are pretty common

mlg@lemmy.world · 2 pts · 212d

People talking about history without mentioning the laziest answer is to use an alias, which bash usually has ll = la -la or my personal preference is ll = ls -lAh (list + Everything except . and .. + human readable file size)

nil@piefed.ca · 1 pts · 213d

is yazi allowed?