Live data from Hacker News

Shell Tricks That Make Life Easier (and Save Your Sanity)

blog.hofstede.it

151–160 of 287 posts

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#151
post #22

Earlier quoted context omitted.

My biggest complaint about the fish shell is the lack of true vi mode. They attempt to emulate it and it works to some degree, but it's no comparison to readline's implementation.

Have you tried a recent version? An issue I opened about this years ago was finally closed, they claim it’s fixed now. I haven’t tried the purported fix, though.

Yes. It has improved, but it's still not there, and probably never will be. See my reply to your sibling comment.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#152
post #26

What confuses me is that Ctrl+Y "yank" means the opposite of what it means in Vim. Certainly does not help with keeping my sanity.

It all depends on your perspective.

Are you yanking into your kill ring or yanking out of your kill ring? I had trouble with yanking and killing until I realized the complement to yanking, killing, only makes sense in the into-the-kill-ring" direction, so yanking must be out of the kill ring.

When I use vim, which I don't think has a kill ring but registers, I think I am yanking into a register and then pasting from a register later.

So, just ask yourself this: "are you using a kill ring or register to store your text?" and the answer becomes clear.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#153
post #121

Earlier quoted context omitted.

> assuming some comfort with emacs is presumably OK in a manual for the software! How do you get familiar with the software, if the manual expects you to be an expert in it already?

Not sure if it did at the time, but today emacs comes with a tutorial. You’re not expected to learn it by starting on page 1 of the manual.

Why not? I expect to learn how to use a software by reading its manual.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#154

One thing I find life-changing is to remap the up arrow so that it does not iterates through all commands, but only those starting with the characters I have already written. So e.g. I can type `tar -`, then the up arrow, and get the tar parameters that worked last time. In zsh this is configured with bindkey "^[OA" up-line-or-beginning-search # Up bindkey "^[OB" down-line-or-beginning-search # Down

This is the default `fish` shell behavior. Type anything, up/down keys to iterate through full commands that containing the term; alt + up/down to iterate through args containing the term.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#155
post #111

Earlier quoted context omitted.

This reminds me of an excerpt from an old Emacs manual: . . . if you forget which commands deal with windows, just type @b[ESC-?]@t[window]@b[ESC]. This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world. I think the better advice for command-line editing would be to set up the mouse.

> This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world. I think it's a question of context and familiarity. To a vim user, like me and, I assume, ahmedfromtunis, their examples do indeed seem simple and natural. Presumably, to an emacs user, the example you quote (if it's quoted literally—I don't use emacs and can't even tell) is just as natural, and assuming som…

The example confusingly includes some weird markup. It's just saying press `ESC-?` then type "window" to search for window commands. These isn't even valid in modern Emacs. The equivalent is `C-h` followed by `a` then type "window".

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#156

One thing I find life-changing is to remap the up arrow so that it does not iterates through all commands, but only those starting with the characters I have already written. So e.g. I can type `tar -`, then the up arrow, and get the tar parameters that worked last time. In zsh this is configured with bindkey "^[OA" up-line-or-beginning-search # Up bindkey "^[OB" down-line-or-beginning-search # Down

Heh. I've done this since forever, but I use PgUp and PgDn so I can retain the original meaning of the up arrow key.

When I was on ubuntu it was easy to uncomment a couple lines in /etc/inputrc for this

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#158
Just recently, I came up with this in my .bashrc, basically a "deep cd" command:

    dcd() {
        # If no argument is given, do nothing
        [ -z "$1" ] && return

        # Find the first matching directory under the current directory
        local dir
        dir=$(find . -type d -path "*$1*" -print -quit 2>/dev/null)

        # If a directory was found, cd into it
        [ -n "$dir" ] && cd "$dir"
    }
I thought this would be way too slow for actual use, but I've come to love it.

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#159
post #64

My header on top of every script #!/usr/bin/env bash set -eEuo pipefail # shellcheck disable=SC2034 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #######################################################

I'd suggest `pwd -P` to resolve symlinks too. (if you use DIR to call/source neighbouring scripts).

Re: Shell Tricks That Make Life Easier (and Save Your Sanity)

#160
post #122

Earlier quoted context omitted.

From the atuin.sh website > Sync your shell history to all of your machines I think of my shell history as very machine specific. Can you give some insights on how you benefit from history sync? If you use it.

Same, I find shared history not very useful. However what I do find useful is eternal history. It's doable with some .bashrc hacks, and slow because it's file based on every command, but: - never delete history - associate history with a session token - set separate tokens in each screen, tmux, whatever session - sort such that backward search (ctrl-R) hits current session history first, and the rest second Like half…

[deleted]
Post reply on HN