Shell Tricks That Make Life Easier (and Save Your Sanity)
161–170 of 287 posts
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#162Earlier 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…
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#163Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#164Just 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…
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#165One 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
## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forwardRe: Shell Tricks That Make Life Easier (and Save Your Sanity)
#166Earlier quoted context omitted.
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)
#167I knew most of these but the $_ variable and "ESC + ." to reference or insert the last argument of the previous command. I can see getting some use out of that, so thanks for posting.
for the last argument
* + "."
if you want the -th argument:
* + "_" # n times :=)
* + "."
cheers a..z
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#168 # Use F2 to edit the current command line:
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^[OQ' edit-command-line # f2 is ^[OQ; to double check, run `xargs` and then press f2Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#169Earlier 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…
First, as for speed and responsiveness, if there is a degradation, it is imperceptible to me. I wouldn't have a clue that my interactive shell is slowing down because it is logging a command to ~/.persistent_history.
My persistent_history is 4MB and has been migrated from machine to machine as I've upgraded, it's never felt slow to edit with (neo)vim or search with system supplied grep.
Eli's way of doing it also includes the timestamps for all commands, so it's easy to trace back when I had run the command, and duplicates are suppressed. In fact my longest persistent_history goes back to 2019-07-04, so I've been using it for quite some time now.
But the larger point I wanted to make is that I wouldn't feel comfortable switching this, in my opinion, quite efficient setup to displace it with an sqlite database. That would require a special tool to drill through the history and search rendering simple unix utilities useless. As Eli suggested, if your history gets too big, simply rotate the file and carry on. I have the alias phgrep to grep ~/.persistent_history, but I can easily have another alias to grep ~/.persistent_history*.
[1]: https://eli.thegreenplace.net/2013/06/11/keeping-persistent-...
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#170Using the terminal becomes much more cozy and comfortable after I activate vim-mode. A mistake 3 words earlier? No problem: 3bcw and I'm good to go. Want to delete the whole thing? Even easier: cc I can even use v to open the command inside a fully-fledged (neo)vim instance for more complex rework. If you use (neo)vim already, this is the best way to go as there are no new shortcuts to learn and memorize.
A mistake 3 words earlier?
meta-bbbd (not as elegant, I admit)
delete the whole thing?
ctrl-ak (this is even quicker than vim, especially if capslock is mapped to ctrl)
the control-based emacs movements work system-wide on macos btw. I am using ctrl-p and ctrl-n to go up and down lines, ctrl-a and ctrl-e to go to beginning and end of lines while writing this comment in by browser (which has vimium extension)
Sometimes I wish vim just had full emacs bindings while in insert mode. But I don't like to mess with defaults too much.
I keep thinking I should give vim readline a try though, so maybe today. Thanks for the comment.