• Voytrekk@sopuli.xyz
    link
    fedilink
    English
    arrow-up
    2
    ·
    4 hours ago

    Great article. I have leanred a lot of these tricks and shortcuts over the years yet I still learned quite a few things that would be useful.

    Particularly that you can paste what you cleared with ctrl+U. No more opening a second tab or creating an additional ssh connection.

  • Badabinski@kbin.earth
    link
    fedilink
    arrow-up
    5
    ·
    6 hours ago

    set -e: Exit on error. Very useful, but notoriously weird with edge cases (especially inside conditionals like if statements, while loops, and pipelines). Don’t rely on it blindly as it can create false confidence. (Pro-tip: consider set -euo pipefail for a more robust safety net, but learn its caveats first.)

    while I appreciate that the author mentions how weird this is, nobody is going to learn all the caveats correctly. Don’t use set -e. Don’t use set -e. Don’t use set -e. It’s a shit ass broken ass fucked feature that half of nobody understands well. Here’s a great wiki page explaining why it’s trash: https://mywiki.wooledge.org/BashFAQ/105

    People like Go, and Go requires you to manually and stupidly handle every possible error case. Why not do the same for shell? It’s really quite easy:

    #!/usr/bin/env bash
    echoerr() { echo "$@" 1>&2; }
    
    die() {
      message="$1"; shift
      exit_code="${1:-1}"
      echoerr "$message"
      exit "$exit_code"
    }
    
    temp_dir="$HOME/tmp"
    mkdir -p "$temp_dir" || die "Failed to make persistent temporary dir $temp_dir"
    lc_dir="$(mktemp -d -p "$temp_dir")" || die "Failed to make target dir in $temp_dir"
    

    Look at that, descriptive error messages! And it doesn’t depend on a shell feature that is inconsistent between versions with no good documentation about all of the fucked up caveats.

  • Undearius@lemmy.ca
    link
    fedilink
    English
    arrow-up
    13
    ·
    8 hours ago

    I’ve seen a few of these “shell tricks” articles. This one I actually learned quite a few, which I will promptly forget when I actually need to use them.

    • Ŝan • 𐑖ƨɤ@piefed.zip
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      8
      ·
      7 hours ago

      I keep a text file full of þese sorts of þings. Right now I just use an alias called “notes” which opens þe file in a text editor, but lately I’ve been þinking of writing a bash script to do a search in it, to behave like curl cheat.sh/restic, but tag-based. Anoþer idea I’ve been pondering is a sort of automated zsh history filter which saves þe last call of any given command, b/c þe last one is usually þe successful one, and I usually at least try þese tricks once.

      Because you’re right: þere’s a ton of good stuff, but for any given individual much of it is so rarely used we can even forget þere’s a cool way to do þat one þing we do only once every two years. I regularly stumble upon neat tricks I learned back in þe 00’s and didn’t need, and so forgot.

      • theherk@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        9 hours ago

        They’re common in clouds like Azure, AWS, etc. Life is better with ssh, but sometimes these are useful for bastions.

      • MummifiedClient5000@feddit.dk
        link
        fedilink
        English
        arrow-up
        2
        ·
        8 hours ago

        I prefer an actual client, especially because I press CTRL+w before my brain sets in, but there are plenty of examples. My latest encounter was Rancher, a k8s management thing.

        But a client running in a browser window does not imply any remotely exploitable vulnerabilities.

  • ExLisper@lemmy.curiana.net
    link
    fedilink
    English
    arrow-up
    4
    arrow-down
    2
    ·
    6 hours ago

    Here’s a real shell trick for you:

    Remove the arrow keys from you keyboard for a month or two.

    Seriously, do it. Do you know how to jump to the beginning of the line? The end? Move one word back? One character back? After a month without arrow keys you will know, trust me.

  • CallMeAl (like Alan)@piefed.zip
    link
    fedilink
    English
    arrow-up
    9
    ·
    9 hours ago

    Great article but this shouldn’t be called “Tricks” it should be called Shell Basics. I’m old enough to remember taking an Intro To Unix course and there was an entire day on the shell where these types of commands were presented as essential learning.

  • john_lemmy@slrpnk.net
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    8 hours ago

    I use CTRL+D a lot, but I didn’t know it was a send EOF command. Why does that close the session / terminal?

    Also, the undo shortcut is also pretty nice (CTRL+_ ?) and missing there

  • MonkderVierte@lemmy.zip
    link
    fedilink
    English
    arrow-up
    8
    arrow-down
    3
    ·
    edit-2
    10 hours ago

    Please make the site respect my color setting by default.

    It’s a sunny spring day.

  • brsrklf@jlai.lu
    link
    fedilink
    English
    arrow-up
    4
    ·
    10 hours ago

    I was expecting some cool Mario strats

    I’m always using “clear” to just get rid of my console’s output. I think it has something to do with me remembering I used that on my old 80’s computer, trying it out on a bash long after that and “oh, that works here too, that’s convenient”.

    Reset looks like it does more stuff, but I don’t know if that’s useful for this use case.

    • lemmydividebyzero@reddthat.comOP
      link
      fedilink
      English
      arrow-up
      5
      arrow-down
      6
      ·
      10 hours ago

      I asked this myself, too. AI response:

      clear: clears the visible screen (sends the terminal’s “clear” sequence); usually fast and does not change terminal settings or fully reinitialize scrollback.

      reset: fully reinitializes the terminal (sends init strings, resets modes/attributes, may reconfigure terminfo/baud, and clears); slower and used to recover from garbled output or broken state.

  • MonkderVierte@lemmy.zip
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    9 hours ago

    alias please='sudo !!' would that work?

    Edit: nope. Why not?
    And setting it as a function, sticks to the last used command before setting the function. Fuck.