Live data from Hacker News

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

blog.hofstede.it

71–80 of 287 posts

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

#72
Regarding history: I have a function in my ZSH config which excludes certain things from the history. Especially things that can break stuff when my sausage fingers CTRL-R the wrong thing

Something like this:

    # Prevent certain strings from appearing in the history
    # Anything starting with a leading space is ignored
    # Anything containing "--force" or "whatever" is ignored
    function zshaddhistory() {
      emulate -L zsh
      if ! [[ "$1" =~ "(^ |--force|whatever)" ]] ; then
          print -sr -- "${1%%$'\n'}"
          fc -p
      else
          return 1
      fi
    }

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

#74
post #38

What I hate is that if you start a command with a space it is not recorded in the history. This happens often when copy+pasting commands. I know you can turn it off but still ... this drives me mad.

AFAIK that setting is opt-in, at least in Bash.

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

#75
I've been using a lot of key combinations and I wasn't aware of these two, and I really think these are awesome additions to handling the console. Thank you for showing me. I've only been using it for 22 years, but I haven't come across these :D

`CTRL + U and CTRL + K CTRL + W`

What I like about these key combinations is that they are kind of universal. A lot of programs on Linux and Mac support all these key combinations out of the box. And that's like a game changer in productivity, especially jumping to the start or the end of the line or jumping forward and backward per word is making working only with the keyboard so much more nice. And in editors together so AVY, you can even get a faster flow of jumping around.

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

#77

Earlier quoted context omitted.

What does it provide over mycmd1 #| mycmd2

Theirs "turns off" one element of a pipeline; yours turns off everything after a certain point. This will output the stdout of mycmd1: mycmd1 #| mycmd2 | mycmd3 This will output the stdout of mycmd3: mycmd1 | \# mycmd2 | mycmd3

Can you explain to me why either of these is useful?

I've somehow gotten by never really needing to pipe any commands in the terminal, probably because I mostly do frontend dev and use the term for starting the server and running prodaccess

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

#78

I'd advise against using sudo !! though since it adds the command to history and then it's very easy to accidentally trigger, running some undesired command as root without any prior confirmation. IMO pressing up, Ctrl-A and typing "sudo " isn't much longer but saves you from running unknown commands as root by accident

Prepend your command with a space and now your command is not saved in the history.

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

#79

Earlier quoted context omitted.

I've been a (n)vim user for 20+ years now, but I hate vi-mode in the shell. However if I feel that I need to do a complex command, I just do ctrl-x+e to open up in neovim (with EDITOR=nvim set). I find it a good middle ground.

Huh. I don’t use vi-mode for more than jumping to the beginning or end of a line, which I like a lot.

I'm a vim user but in the shell I use Ctrl-a and Ctrl-e to get to the beginning and end. If I need more editing I use Ctrl-x Ctrl-e to hop into vim.
Post reply on HN