# it's in my PATH but can't remember where
which myscript
vi `!!` # 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 f2Be careful working CTRL + W into muscle memory though, I've lost count of how many browser tabs I've closed by accident...
One thing I dislike about brace expansions is that they don't play nicely with tab completion. I'd rather have easy ways to e.g. duplicate the last token (including escaped/quoted spaces), and delete a filename suffix. And, while I'm on that topic, expand variables and `~` immediately (instead of after pressing enter).
A mistake 3 words earlier? No problem: <esc>3bcw and I'm good to go.
Want to delete the whole thing? Even easier: <esc>cc
I can even use <esc>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.
In zsh this is configured with
bindkey "^[OA" up-line-or-beginning-search # Up
bindkey "^[OB" down-line-or-beginning-search # Down 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. He had in his path a script called `\#` that he used to comment out pipe elements like `mycmd1 | \# mycmd2 | mycmd3`. This was how the script was written:
```
#!/bin/sh
cat
```printf %s\\n "$_"
`| sudo tee file` when current user does not have permission to >file
For the CTRL + R tip, you can make it even better if you install fzf. Massively improves searching through history. It's worth the install just for that one feature.
Best thing I ever did as a dev was start spending more time in the terminal. Getting familiar with the tools and how they interact makes life so much easier.
The vi editing mode is always present in ksh, but is optional in dash. If present, the POSIX standard requires that "set -o vi" enable this mode, although other methods to enable it are not prohibited (such as inputrc for bash/readline), and as such is a "universal trick."
The article is relying on some Emacs mode, which is not POSIX.
$_ is not POSIX if I remember correctly.
History in vi mode is easier, just escape, then forward slash (or question mark) and the search term (regex?), then either "n" or "N" to search the direction or its reverse.
I've seen a lot of people who don't like vi mode, but its presence is the most deeply standardized.
I tried this in zsh and it wasn't the default behaviour which immediately made me nope from the shell altogether, among all the other quirks. I've just been using bash for far too long to switch to something different.
[0] https://eli.thegreenplace.net/2013/06/11/keeping-persistent-...
Quite a few useful ones
I remember using `cat -v` before learning that `xargs` exists… or maybe before `xargs` actually existed on systems I used :)
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
}You're typing a long command, then before running it you remember you have to do some stuff first. Instead of Ctrl-C to cancel it, you push it to history in a disabled form.
Prepend the line with # to comment it, run the commented line so it gets added to history, do whatever it is you remembered, then up arrow to retrieve the first command.
$ long_command
<Home, #>
$ #long_command
<Enter>
$ stuff_1 $ stuff_2
<Up arrow a few times>
$ #long_command
<home, del>
$ long_command
And not only cd. Gotta love 'git checkout -'
Stuff like NVM or Oh My ZSH will add a few seconds to your shell startup time.
#!/usr/bin/env bash
set -eEuo pipefail
# shellcheck disable=SC2034
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
#######################################################<esc> puts you into vi mode at the cli prompt with all the semantics of the editor.
These carpal tunnel riddled hands can’t be bothered to reach for ctrl or alt let alone arrow keys.
It's often faster than hitting CTRL+C and waiting for process cleanup, especially when many resources are used. Then you can do e.g. `kill -9 $(jobs -p)` to kill the stopped tasks.
`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.
> The Backspace Replacements
Also known as "emacs editing mode". Funnily enough, what POSIX mandates is the support for "vi editing mode" which, to my knowledge, almost nobody ever uses. But it's there in most shells, and you can enable it with "set -o vi" in e.g. bash.
Close tab.
I ought to migrate away from shell scripting and just keep the shell for interactive use. Unfortunately I have cursed myself by getting competent-ish with P. shell and Bash scripting. Meaning I end up creating maintenance headaches for my future self.
(Echoes of future self: ... so I asked an LLM to migrate my shell scripts to Rust and)
Anyway with the interactive shell stuff. Yeah the I guess Readline features are great. And beyond that I can use the shortcut to open the current line in an editor and get that last mile of interactivity when I want it. I don’t really think I need more than that?
I tried Vim mode in Bash but there didn’t seem to be a mode indicator anywhere. So dropped that.
Edit: I just tested in my Starship.rs terminal: `set -o vi`. Then I got mode indicators. Just with a little lag.
I've never used the majority of these tricks for decades, except for brace expansion, process substitutions, and complex redirections.
$ some_long_command -with -args -easily -forgotten # thatspecialthing
... Some weeks later .. $ CTRL-R<specialthing>
.. finds: $ some_long_command -with -args -easily -forgotten # thatspecialthing
Need to see all the special things you've done this week/whenever? $ history | grep "\#"
...Makes for a definite return of sanity ..
Also, increase your `$HISTSIZE` to more than you think you would need, there have been cases where it helped me find some obscure command I ran like 3 years before.
Simple, no need to learn any commandline these days.
I used to use arch and all, and managed many big projects. I find little value in learning new tools anymore, just feed it docs and it generated working plan most of the time
Now I've moved to coding in Haskell, which i find suits me better than wasting my time with cli and exploring what options all these cli tools have.
1. Load about:keyboard
2. Find "Close tab" and click "Clear" or "Change".
This hurts.
Also, for the shell, if you do C+w, you can "paste" it back using C+y. Assuming you have not removed that configuration.
You're telling me!!!
(I use vim daily, with multiple splits in a single instance.)
Yeah, pressing Ctrl-W accidentially is a pain sometimes ... but Ctrl-Shift-T in Firefox is a godsend.
You also mention there being "little value", when your proposed approach costs literal money in form of API/token usage (when using hosted models).
> Now I've moved to coding in Haskell
You might like https://hackage.haskell.org/package/turtle or http://nellardo.com/lang/haskell/hash/
As someone who works mostly in WSL and has to use PS occasionally, it really reduces the overhead of the context switch.
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.
I really need to get around to playing with it more. I just hope that especially now with genAI that it's not too late for learning it further.
## arrow up
"\e[A":history-search-backward
## arrow down
"\e[B":history-search-forward "\e[A": history-search-backward
"\e[B": history-search-forward #!/bin/sh
$*
that's my `~/bin/noglob` file, so when I call a zsh script from bash that uses `noglob`, it doesn't blow up.Or maybe you don’t use SHIFT. Can’t recall right now. My fingers know but I’m not at a computer.
Anyway, browser menus can also show you recently closed tabs and bring them back.
stty werase undef
bind '"\C-w": backward-kill-word'
source: https://superuser.com/questions/212446/binding-backward-kill...One thing I do is configure my keyboard so that "modifier+{ijkl}" mimicks the inverted T arrows key cluster. So there's never a need for me to reach for the arrow keys. And {ijk} makes more sense than vi's {hjkl} and is faster/more logical/less key fingers travel. The nice thing is: as I do this at the keyboard level, this works in every single map. "modifier" in my case is "an easily reachable key in a natural hand position on which my left thumb is always resting" but YMMV.
I set that up years ago and it works in every app: it's gorgeous. Heck, I'm using it while editing this very message for example.
And of course it composes with SHIFT too: it's basically arrow keys, except at the fingers' natural positions.
To take advantage of the "leading space" one, I have this, to mark some commands that I never want to record:
unhist () {
alias $1=" $1"
}
unhist unhist
unhist fzf
unhist rghist #custom command that greps .zhistory,...I will never understand people like you.
. . . 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.
Doing control+o in insert mode temporarily places you into normal mode so that you can execute one normal-mode command, and then go back to insert mode again--no need to hit 'i' again.
So, instead of '<esc>cc', '<c-o>S'.
<esc>3bcw
What is your keyboard layout? This looks like a crime against humanity on a regular qwerty kb.For further life-changing experience... add aliases to .bash_aliases
alias gph='history | grep --colour -i '
alias gpc='grep --colour -Hin '
#if gnu time is installed
alias timef='/usr/bin/time -f "tm %E , cpu %P , mem %M" ' $ echo foo | tr fo FO | sed 's/FOO/BAR/'
BAR
$ echo foo | ${IFS# tr fo FO | } sed 's/FOO/BAR/'
foo
It's nice to have a way to both /* ... */ and // ...
in shell scripts though: foo \
| bar ${IFS Do the bar. Do it. } \
| baz
* in the best possible way, like it's awful - I hate I didn't think of thatFun fact: despite having absolutely no menu entry for it, and I believe not even a command available with Ctrl+Shift+P, Vscode supports Ctrl+Shift+T to re-open a closed tab. Discovered out of pure muscle memory.
That, and Ctrl-N. No more forest of blank browser windows when using a terminal emulator in a web page!
(Firefox only)
With zsh, I prefer to use alt-q which does this automatically (store the current line, display a new prompt, then, after the new command is sent, restore the stored line). It can also stack the paused commands, e.g.:
$ cp foo/bar dest/ <alt-q>
$ wcurl -o foo/bar "$URL" <alt-q>
$ mkdir foo <enter> <enter> <enter>
If you are feeling brave
They don't matter much to me.
I do prefer vi bindings at the same time though. Vi bindings and mouse support complement each other well, you don't have to choose one or the other, just use whichever feels most natural and convenient in that exact moment.
edit: And of course, CTRL+R, the best time saver of all
I WANT to love it - and if I was only ever working on one, or a small number of systems that I was the only one working on I’d probably do it. I’m ALL about customizing my environment.
However ssh into various servers through the day (some of which are totally ephemeral), and having to code switch my brain back and forth between vim mode and emacs mode in the shell would just slow me down and be infuriating each time I connect to a new box.
bind '"\e[A"':history-search-backward
bind '"\e[B"':history-search-forwardOne I came up and that I use all the time:
alias wl='wc -l'
I use it so much I sometimes forget it's not stock. $ asdf<C-w>
$ # now kill ring is ["asdf"]
$ qwerty<C-a><C-k>
$ # now kill ring is ["qwerty", "asdf"]
$ <C-y> # "yank", pastes the thing at the top of the kill ring
$ qwerty<M-y> # "yank-pop", replaces the thing just yanked with the next
# thing on the ring, and rotates the ring until the next yank
$ asdfhttps://junegunn.github.io/fzf/search-syntax.
The $ and bang and exact search are neat, but the bit at the bottom as to why `gadd` or `gas` is a better search for `git add something` than something with full words and spaces is a revelation when first using fzf.
You would never pipe the output of a command to `cd` so the `-` shortcut couldn't be helpful to cd as-is. So rather than invent yet another shortcut to memorize for `cd` they reused the existing one which otherwise would be redundant, which I appreciate at least.
But git is simply being consistent with the shell to further reduce the cognitive complexity of reusing shell commands you're used to in analogous git contexts.
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 some comfort with emacs is presumably OK in a manual for the software!
The one you suggest however requires 4 strokes (ctrl then o then shift then s), 4 keys (ctrl, o, shift, s) and 2 combinations.
The "cc" sequence deletes the line and switches automatically to insert mode. To forgo the switch, the sequence then becomes "dd".
foo |
bar |
baz
You don't have to use backquotes, AND, it allows you to comment line by line, because there's no backslash messing with the parser.I also use a last `|\ncat` so you can delete any line and you don't have to worry about the last line being a bit different than the rest
I created a list of similar tricks in https://github.com/kidd/scripting-field-guide in case anyone wants to take a look
This will output the stdout of mycmd1:
mycmd1 #| mycmd2 | mycmd3
This will output the stdout of mycmd3: mycmd1 | \# mycmd2 | mycmd3Ctrl+Shift+T will undo your recent tab closures in reverse order. The tabs maintain their history as well.
I am very surprised at how many people in here don’t seem to know that. I learned about Ctrl+Shift+T before I learned about Ctrl+W. I was using the middle mouse button on a tab to close tabs before then.
There is a distinct, visceral kind of pain in watching an otherwise brilliant engineer hold down the Backspace key for six continuous seconds to fix a typo at the beginning of a line.
We’ve all been there. We learn ls, cd, and grep, and then we sort of… stop. The terminal becomes a place we live in-but we rarely bother to arrange the furniture. We accept that certain tasks take forty keystrokes, completely unaware that the shell authors solved our exact frustration sometime in 1989.
Here are some tricks that aren’t exactly secret, but aren’t always taught either. To keep the peace in our extended Unix family, I’ve split these into two camps: the universal tricks that work on almost any POSIX-ish shell (like sh on FreeBSD or ksh on OpenBSD), and the quality-of-life additions specific to interactive shells like Bash or Zsh.
These tricks rely on standard terminal line disciplines, generic Bourne shell behaviors, or POSIX features. If you SSH into an embedded router from 2009, a fresh OpenBSD box, or a minimal Alpine container, these will still have your back.
Why shuffle character-by-character when you can teleport? These are standard Emacs-style line-editing bindings (via Readline or similar), enabled by default in most modern shells.
CTRL + W: You’re typing /var/log/nginx/ but you actually meant /var/log/apache2/. You have two choices: hold down Backspace until your soul leaves your body, or hit CTRL + W to instantly delete the word before the cursor. Once you get used to this, holding Backspace feels like digging a hole with a spoon.
CTRL + U and CTRL + K: You typed out a beautifully crafted, 80-character rsync command, but suddenly realize you need to check if the destination directory actually exists first. You don’t want to delete it, but you don’t want to run it. Hit CTRL + U to cut everything from the cursor to the beginning of the line. Check your directory, and then hit CTRL + Y to paste (“yank”) your masterpiece right back into the prompt. (CTRL + K does the same thing, but cuts from the cursor to the end of the line.)
CTRL + A and CTRL + E: Jump instantly to the beginning (A) or end (E) of the line. Stop reaching for the Home and End keys; they are miles away from the home row anyway.
ALT + B and ALT + F: Move backward (B) or forward (F) one entire word at a time. It’s the arrow key’s much faster, much cooler sibling. (Mac users: you usually have to tweak your terminal settings to use Option as Meta for this to work).
reset (or stty sane): While strictly more of a terminal recovery tip than an interactive shell trick, it belongs here. We’ve all done it: you meant to cat a text file, but you accidentally cat a compiled binary or a compressed tarball. Suddenly, your terminal is spitting out ancient runes and Wingdings, and your prompt is completely illegible. Instead of closing the terminal window in shame, type reset (even if you can’t see the letters you’re typing) and hit enter. Your terminal will heal itself.
CTRL + C: Cancel the current command immediately. Your emergency exit when a command hangs, or you realize you’re tailing the wrong log file.
CTRL + D: Sends an EOF (End of File) signal. If you’re typing input to a command that expects it, this closes the stream. But if the command line is empty, it logs you out of the shell completely-be careful where you press it.
CTRL + L: Your terminal is cluttered with stack traces, compiler spaghetti, and pure digital noise. Running the clear command works, but what if you’re already halfway through typing a new command? CTRL + L wipes the slate clean, throwing your current prompt right up to the top without interrupting your train of thought.
cd -: The classic channel-flipper. You’re deep down in /usr/local/etc/postfix and you need to check something in /var/log. You type cd /var/log, look at the logs, and now you want to go back. Instead of typing that long path again, type cd -. It switches you to your previous directory. Run it again, and you’re back in logs. Perfect for toggling back and forth.
pushd and popd: If cd - is a toggle switch, pushd is a stack. Need to juggle multiple directories? pushd /etc changes to /etc but saves your previous directory to a hidden stack. When you’re done, type popd to pop it off the stack and return exactly where you left off.
> file.txt: This empties a file completely without deleting and recreating it. Why does this matter? It preserves file permissions, ownership, and doesn’t interrupt processes that already have the file open. It’s much cleaner than echo "" > file.txt (which actually leaves a newline character) or rm file && touch file.
$_: In most shells, $_ expands to the last argument of the previous command-especially useful interactively or in simple scripts when you need to operate on the same long path twice:
mkdir -p /some/ridiculously/long/path/newdir && cd "$_"
No more re-typing paths or declaring temporary variables to enter a directory you created a second ago.
If you are writing shell scripts, put these at the top immediately after your shebang. It will save you from deploying chaos to production.
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.)set -u: Treats referencing an unset variable as an error. This protects you from catastrophic disasters like rm -rf /usr/local/${MY_TYPO_VAR}/* accidentally expanding into rm -rf /usr/local/*.If you’re on a Linux box or using a modern interactive shell, these are the tools that make the CLI feel less like a rusty bicycle and more like something that actually responds when you steer.
CTRL + R: Reverse incremental search. Stop pressing the up arrow forty times to find that one awk command you used last Tuesday. Press CTRL + R, start typing a keyword from the command, and it magically pulls it from your history. Press CTRL + R again to cycle backwards through matches.
!!: This expands to the entirety of your previous command. Its most famous use case is the “Permission denied” walk of shame. You confidently type systemctl restart nginx, hit enter, and the system laughs at your lack of privileges. Instead of retyping it, run:
sudo !!
It’s your way of telling the shell, “Do what I said, but this time with authority.”
CTRL + X, then CTRL + E: You start typing a quick one-liner. Then you add a pipe. Then an awk statement. Soon, you’re editing a four-line monster inside your prompt and navigation is getting difficult. Hit CTRL + X followed by CTRL + E (in Bash; in Zsh, this needs configuring). This drops your current command into your default text editor (like Vim or Nano). You can edit it with all the power of a proper editor, save, and exit. The shell then executes the command instantly.
fc: The highly portable, traditional sibling to CTRL+X CTRL+E. Running fc opens your previous command in your $EDITOR. It works across most shells and is a fantastic hidden gem for fixing complex, multi-line commands that went wrong.
ESC + . (or ALT + .): Inserts the last argument of the previous command right at your cursor. Press it repeatedly to cycle further back through your history, dropping the exact filename or parameter you need right into your current command.
!$: The non-interactive sibling of ESC + .. Unlike ESC + . (which inserts the text live at your cursor for you to review or edit), !$ expands blindly at the exact moment you hit enter. (Pro-Tip: For scripting or standard sh, use the $_ variable mentioned earlier instead!)
Brace expansion is pure magic for avoiding repetitive typing, especially when doing quick backups or renames.
The Backup Expansion: Need to edit a critical config file and want to make a quick backup first?
cp pf.conf{,.bak}
The shell expands this seamlessly into cp pf.conf pf.conf.bak.
The Rename Trick:
mv filename.{txt,md}
This expands to mv filename.txt filename.md. Fast, elegant, and makes you look like a wizard.
Need multiple directories? mkdir -p project/{src,tests,docs} creates all three at once.
<(command): Treats the output of a command as if it were a file. Say you want to diff the sorted versions of two files. Traditionally, you’d sort them into temporary files, diff those, and clean up. Process substitution skips the middleman:
diff <(sort file1.txt) <(sort file2.txt)
** (Globstar): find is a great command, but sometimes it feels like overkill. If you run shopt -s globstar in Bash (it’s enabled by default in Zsh), ** matches files recursively in all subdirectories. Need to find all JavaScript files in your current directory and everything beneath it?
ls **/*.js
No find command required.
CTRL + Z, then bg, then disown: You started a massive, hour-long database import task, but you forgot to run it in tmux or screen. It’s tying up your terminal, and if your SSH connection drops, the process dies. Panic sets in.
CTRL + Z to suspend (pause) the process.bg to let it resume running in the background. Your prompt is free!disown to detach it from your shell entirely. You can safely close your laptop, grab a coffee, and the process will survive.command |& tee file.log: Standard pipes (|) only catch standard output (stdout). If a script throws an error (stderr), it skips the pipe and bleeds directly onto your screen, missing the log file. |& pipes both stdout and stderr (it’s a helpful shorthand for 2>&1 |).
Throw in tee, and you get to watch the output on your screen while simultaneously saving it to a log file. It’s the equivalent of watching live TV while recording it to your DVR.
The shell is a toolbox, not an obstacle course. You don’t need to memorize all of these today. Pick just one trick, force it into your daily habits for a week, and then pick another. Stop letting the terminal push you around, and start rearranging the furniture. It’s your house now.
lazy_nvm() {
unset -f nvm node npm npx
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
}
nvm() { lazy_nvm; nvm "$@"; }
node() { lazy_nvm; node "$@"; }
npm() { lazy_nvm; npm "$@"; }
npx() { lazy_nvm; npx "$@"; }Then one day, I was trying to setup MySQL on a personal Linux machine, and it wouldn't let me use my "standard password" for the admin account. I knew I could just use a different one, but I really wanted to know what the problem was. Took a long time, and I don't remember how I figured it out, but I eventually tracked it to the password ending with '!!'.
It took a while to put it together, and I never confirmed with the dns host support it's what fixed the issue but, I changed my password there, tried the transfer again, and it worked without any help from support. I suspect my plaintext password played some part in a script used in the transfer process, and was outputting the previous command in place of the !! I wish I had asked them if that was it, but if it was, they would have to admit to having my plain text password, or lie about it.
^Z sends TSTP (not STOP, though they have the same default behavior) to suspend; some programs catch this to do terminal state cleanup before re-raising it to accept the suspension. Catching it to do full backout doesn't make as much sense because the program anticipates being resumed.
^\ sends QUIT, which normally causes a core dump and is rarely caught. If you have core dumps disabled (via ulimit -c 0 or other system configuration) then you can often use it as a harder version of ^C; this is how I would tend to get out of ‘sl’ in places where I found it unwantedly installed.
if you care about perf, fnm is better/faster/cleaner than nvm. (also, mise is able to manage "all the things", not just node)
IME omzsh slowness usu relates to overloading it w plugins, which I've never found a need for...
Notably, these keybindings are it's default map, which comes from the GNU's project editor Emacs. But, there is also the POSIX-compliant, but not-default, editing mode based on Bill Joy's visual editor (vi).
Regarding experience, I'm also struck by how many "experienced" engineers are just clueless with the keyboard.
$ cat
^Z[1] + Stopped cat
$ kill %1Are 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.
bind '"\C-x\C-u": undo'
bind '"\C-_": undo'for the last argument
* <alt> + "."
if you want the -<n>th argument:
* <alt> + "_" # n times :=)
* <alt> + "."
cheers a..z
Why do you disable SC2034?
I don't think not having unused variables prevent me from doing things in my scripts!?
I understand if it's a preference but SC2034 is basically one of my biggest timesavers: in my case unused variables are typically a bug. Except, maybe, ANSI coloring variables at the top of the script.
and i only use sudo to open a root shell. never to run anything directly. i don't want normal and root commands mixed in the same history.
i could keep sudo commands out of the history, but then i don't have any history for stuff done as root.
with tmux i can switch terminals easily, so i am also not tempted to run things as root that i shouldn't despite having a root shell open.
Once you get used to it, it is painful to go back.
<esc>S
Esc exits insert mode (of course) and capital S erases the line and puts you in insert mode at column 0 (just like in (n)vim, right?).
Like I said, maybe I configured that? But 'S' is standard vim-stuff... (I'm not able to double check my config at the moment).
[Edit: right after hitting submit I realized that my way is perhaps "arguably" simpler because I do have to hit shift to get capital S. So I'm also hitting three keys...]
"I typed 'cd di↑' and you're giving me 'pwd'??"
How do you get familiar with the software, if the manual expects you to be an expert in it already?
Completely transformed all of my workflows
If I hit CTRL + ARROW_LEFT 3 times, I am done a lot faster I guess. But I am open to learn, do people really use that and achieve the goal significantly faster?
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
On bash, you can achieve this by setting HISTCONTROL=ignorespace but that's not the default.
shopt -s histverify
shopt -s histreedit
i dont know why they are not the default.
$ {
> echo foo \
> && echo bar \
> || echo baz ;
> }
foo
bar
<^P><^A>$<^F>IFS
${IFS# echo foo && echo bar || echo baz ; }
$ _
There's good and bad to both approaches. I like how I can use () and {} to bracket things and otherwise every line that end in \ is continued. I line-up on the left with the operator, you with indentation. When you use a # style comment, you have to look up and back and forward to see what the operator is you are continuing over to the next line: $ foo |
bar | # ?Do? *the* $bar$ && [do] {it!}
baz
Which only takes an extra neuron or so, but then history... <^P>
$ foo | bar | # ?Do? *the* $bar$ && [do] {it!}
bazMany people these days, including yours truly, have caps-lock mapped to ctrl if held or esc if tapped. That’s good ergonomics and worth considering for any tech-savvy person.
Instead of the 3b I would type bbb (because I agree with you that typing numerals is a pain).
So (caps lock)bbbcw isn’t bad. It’s better than it looks, because if you’re a vim user then it’s just so automatic. “cw” feels like one atomic thing, not two keypresses.
And importantly, it doesn’t involve any chords.
Now let's say the output looks wrong; e.g. we get nothing out. Weird, the previous command looked right, and it doesn't seem to be a problem with the filter we just put on the end. Maybe the filter we added part-way-through was discarding too much, so that the things we actually wanted weren't reaching the later stages; we didn't notice, because everything was being drowned-out by irrelevant stuff that that our latest filter has just gotten rid of.
Tricks like this `\#` let us turn off that earlier filter, without affecting anything else, so we can see if it was causing the problem as we suspect.
As for more general "why use CLI?", that's been debated for decades already; if you care to look it up :-)
> 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.
Using brackets like this is something I never thought of, and it's probably why it's hard for me to process it, but I can see it provides nice annotation capabilities, and it's a more self-contained style.
Thx for sharing!
Your Problem with vim is you don't grok vi
https://stackoverflow.com/questions/1218390/what-is-your-mos...
2. clone it on host_bar in /home/user/src/myproject
If you set filter_mode = "directory", you can recall project specific commands from host_foo for use on host_bar even though you're working on different machines and the search space won't be cluttered with project specific commands for other projects.
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 my corporate brain is in a 11M history file at this point, going back years.
What I would love is to integrate this into the shell better so it's using sqlite or similar so it doesn't feel "sluggish." But even now the pain is worth the prize.
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-...