Navigating around in your shell (blog.meain.io)
from learnbyexample@programming.dev to linux@lemmy.ml on 24 Nov 2023 10:53
https://programming.dev/post/6321543

#linux

threaded - newest

mike_wooskey@lemmy.d.thewooskeys.com on 24 Nov 2023 11:34 next collapse

Thanks for these tips.

QuazarOmega@lemy.lol on 24 Nov 2023 12:24 next collapse

Great stuff! Didn’t know about lf

executivechimp@discuss.tchncs.de on 24 Nov 2023 15:29 next collapse

Good article. Rather than aliasing `cd …/…" etc. I’ve got this function in my setup:

up () {
	local x='' 
	for i in $(seq ${1:-1})
	do
		x="$x../" 
	done
	cd $x
}

This lets me do up 4 to go up 4 directories.

ENipo@lemmy.world on 24 Nov 2023 15:44 next collapse

Oh I really like this. I never had an alias for this since I need to do multiple backwards cds very rarely, but I might just copy this

executivechimp@discuss.tchncs.de on 24 Nov 2023 15:56 next collapse

Go for it. I’ve been using it for years without a problem.

taladar@sh.itjust.works on 24 Nov 2023 16:00 collapse

I have the zsh option autopushd set which calls pushd in interactive shells for every cd, that way 90% of the time when I want to go back up to another path I can just use popd

Astaroth@lemm.ee on 24 Nov 2023 16:09 next collapse

I use Fish and have keybinds for previous and next directory, 99% of the time when going up in a directory it’s to (one of) the previous directory/ies I was in

olafurp@lemmy.world on 24 Nov 2023 17:17 next collapse

You could also do a “up” for one up “upp” for 2 and “upppp” for 4 because of fun

executivechimp@discuss.tchncs.de on 24 Nov 2023 18:28 collapse

True. That is something that could be done.

Specialpatrol@feddit.uk on 24 Nov 2023 20:56 next collapse

Holy shit

beeng@discuss.tchncs.de on 24 Nov 2023 23:27 next collapse

Look into zoxide.

z direc

Will take you to the most used directory starting with “direc” eg “/home/me/random/directory”

executivechimp@discuss.tchncs.de on 25 Nov 2023 08:49 collapse

I’ve tried things like that before but never got on with them. I found when I had many projects with similar directory structures it was easy to end up in the wrong place and took more thought to get to the right place than just cding

beeng@discuss.tchncs.de on 25 Nov 2023 09:07 collapse

The dir’s are the same names or similar? A few extra key strokes to get the fullname should be easier than cd’ing back and forth.

There’s also z foo “space” “tab” as per docs to get interactive list for matches.

But, just a suggestion!

PlexSheep@feddit.de on 26 Nov 2023 11:18 collapse

What I use to automatically extend stuff like ls … to ls …/…/…/…

function expand-dots() {
    local MATCH
    if [[ $LBUFFER =~ '(^| )\.\.\.+' ]]; then
        LBUFFER=$LBUFFER:fs%\.\.\.%../..%
    fi
}

function expand-dots-then-expand-or-complete() {
    zle expand-dots
    zle expand-or-complete
}

function expand-dots-then-accept-line() {
    zle expand-dots
    zle accept-line
}

zle -N expand-dots
zle -N expand-dots-then-expand-or-complete
zle -N expand-dots-then-accept-line
bindkey '^I' expand-dots-then-expand-or-complete
bindkey '^M' expand-dots-then-accept-line

(for zsh)

TunaCowboy@lemmy.world on 24 Nov 2023 16:00 next collapse

Is there a community for people that actually know and use linux or is this just like 'programmer’humor where morons can’t exit vim, use a debugger, or RTFM?

Chewy7324@discuss.tchncs.de on 24 Nov 2023 16:12 collapse

How would you define “knowing” and “using” linux? Many people here don’t use Linux professionally and only on the desktop, so they probably aren’t too familiar with all the features of different cli programs.

Reading a blog post is more accessible than reading a man page. I didn’t know cd -, so reading the post was worth it I’d say.

ouch@lemmy.world on 25 Nov 2023 01:06 collapse

Reading a blog post is more accessible than reading a man page.

I don’t agree with that assessment at all. People should learn to read manpages, instead of being spoon-fed pieces of manpages in inferior form.

Chewy7324@discuss.tchncs.de on 25 Nov 2023 01:12 next collapse

Any program should have a man page, even if it only lists all options. My point is that a blog post helps some people to learn about a program. For example a post often highlights the most important options of a software.

IAm_A_Complete_Idiot@sh.itjust.works on 26 Nov 2023 16:27 collapse

manpages aren’t guides though - they don’t help much in learning new tools, especially complicated ones. They’re comprehensive references, some can literally span hundreds of pages. Useful when you know what you’re doing and what you’re looking for, not great for learning new tools.

Synthead@lemmy.world on 24 Nov 2023 16:05 next collapse

Some of these tips are dangerous. You generally don’t want cause insensitivity in your shell. Also, ls should never be used as a subshell to find files as a part of commands.

hallettj@beehaw.org on 24 Nov 2023 23:30 collapse

I use that r function regularly to go to the git project root. But I call it gtop. I mostly use that and zoxide to get around.