Top
Best
New

Posted by zdw 18 hours ago

Shell Tricks That Make Life Easier (and Save Your Sanity)(blog.hofstede.it)
425 points | 204 comments
stormed 21 seconds ago|
You'll look like the coolest person in the office running `sudo !!`. Another personal favorite of mine is using the --now flag for systemctl to enable & start a service in one command (i.e `systemctl enable --now nginx`)
alberto-m 6 hours ago||
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
bwhaley 6 hours ago||
Once you start using CTRL+r, you may find that you never reach for up arrow again.
pavel_lishin 5 hours ago|||
I'm familiar with ctrl-r, but I still very much like the up-arrow behavior described by that commenter.
flir 3 hours ago||
Looking at it from a "law of least surprise" angle, it's exactly how it should behave.

"I typed 'cd di↑' and you're giving me 'pwd'??"

soraminazuki 1 hour ago||||
Prefix search is faster for the majority of cases. CTRL-r / FZF is useful for the remaining ones.
kuschkufan 6 hours ago||||
And once you want to one-up this look into fzf.
nidnogg 5 hours ago||
And once you get tired of fzf and want something better, you reach for https://atuin.sh.

Completely transformed all of my workflows

seedie 4 hours ago||
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.

__MatrixMan__ 22 minutes ago|||
1. work on a project on host_foo in /home/user/src/myproject

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.

Cyphus 4 hours ago||||
That feature is entirely optional and disabled by default. Atuin stores your shell history locally in a sqlite db regardless of whether you choose to sync it. I thought fzf was fast, but atuin makes it look slow by comparison.
foobarian 4 hours ago|||
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 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.

commandersaki 2 hours ago|||
I just want to give a perspective of someone that uses the 'eternal history' in bash per Eli Bandersky [1] and reluctance to use something like atuin (without/ignoring shared history).

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-...

fragmede 3 hours ago||||
You don't have to setup shared history with Atuin if you don't want to and that's what's holding you back. Otherwise it hits the rest of your requirements. Just don't hesitate to change from the default config.
BeetleB 4 hours ago||||
There is a difference, I believe. Doesn't Ctrl+r do a substring search instead?
imglorp 2 hours ago||
Yes it's different: it will match anywhere in the previous command lines.
noisy_boy 3 hours ago|||
export EDITOR=vi and then hitting Esc puts you into vi mode; k, j to move up/down through history or pressing / to search etc including using regex is all available.
sureglymop 2 hours ago|||
I agree it's a game changer! For bash to do the same I put this in my .inputrc:

    ## arrow up
    "\e[A":history-search-backward
    ## arrow down
    "\e[B":history-search-forward
hebelehubele 3 hours ago|||
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.
Fishkins 2 hours ago|||
I do something similar. I leave up and down arrows alone, but have ctrl+p and ctrl+n behave as you describe.
moebrowne 5 hours ago|||
This can also be achieved with `.inputrc`:

    "\e[A": history-search-backward
    "\e[B": history-search-forward
n8henrie 6 hours ago|||
Did this many years ago (but with bash) -- life changing is an apt way of saying it.
account42 5 hours ago||
Here's the Bash commands for this in case anyone is looking for them

  bind '"\e[A"':history-search-backward
  bind '"\e[B"':history-search-forward
BeetleB 4 hours ago|||
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.
dsp_person 3 hours ago||
When I was on ubuntu it was easy to uncomment a couple lines in /etc/inputrc for this
heresie-dabord 6 hours ago|||
> life-changing

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" '
TacticalCoder 4 hours ago||
I've got many like these I copied from various people over the years.

One 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.
TacticalCoder 4 hours ago||
That's a nice one.

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.

ahmedfromtunis 9 hours ago||
Using the terminal becomes much more cozy and comfortable after I activate vim-mode.

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.

piekvorst 7 hours ago||
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.

mikkupikku 1 hour ago|||
I have yet to see a shell that has mouse enabled line editing support. It should certainly be possible though.

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.

JadeNB 5 hours ago|||
> 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 some comfort with emacs is presumably OK in a manual for the software!

Orygin 4 hours ago|||
> 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?

noisy_boy 3 hours ago|||
I got familiar with vi by reading a book that had the main vi commands listed out. First learnt how to quit without saving changes, the rest was just practice.
umanwizard 4 hours ago||||
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.
Orygin 3 hours ago||
Why not? I expect to learn how to use a software by reading its manual.
umanwizard 2 hours ago||
Surely you can still do that, but starting with the tutorial will be easier and more efficient.
Pay08 4 hours ago|||
By reading introductory material.
matthew-craig 3 hours ago|||
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".
commandersaki 9 hours ago|||
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.
void-star 5 hours ago|||
It’s strange. I have heard this from lots of others too. I think I am an anomaly here. I can’t live without shell vi mode
lenkite 38 minutes ago|||
Same - shell vi mode is critical for intensive terminal sessions.
fp64 3 hours ago|||
You're not alone, I heavily rely on vi mode and often struggle if I'm on someone else's machine and can't use it. I always wonder how you're supposed to work without it but I never dare to ask
Linux-Fan 2 hours ago||
`set -o vi` is quickly typed in anger...
busfahrer 6 hours ago||||
I'm the same and in my opinion this is the best of both worlds. Taking the time to learn some of the regular (emacs-style) shortcuts is one of the best investments I've ever done. Even just CTRL+Y and the likes.

edit: And of course, CTRL+R, the best time saver of all

xtiansimon 7 hours ago||||
Huh. I don’t use vi-mode for more than jumping to the beginning or end of a line, which I like a lot.
wbrd 6 hours ago|||
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.
void-star 4 hours ago||||
It really shines for navigating history. <esc>/ searches history the same way as the editor search function
umanwizard 4 hours ago||||
C-a and C-e are your friend.
irishcoffee 7 hours ago|||
You mean, like the “home” and “end” buttons?
wholinator2 6 hours ago|||
Yeah but those are so far away, i have to hunt for them every time
helterskelter 2 hours ago||||
I used to hate it because I'd sometimes change modes without realizing it, but I began to appreciate it a lot more when I added a mode indicator -- a red 'N' on the rightmost side of the input line.
sudonem 8 hours ago|||
Agree.

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.

dbtc 2 hours ago|||
I use vim a lot but not on the shell

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.

rzmmm 9 hours ago|||
Oh wow I didn't know about this, thank you. The underlying feature is called "readline vi-mode" for folks who want to search more about it.
penguin_booze 7 hours ago|||
> <esc>cc

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'.

soraminazuki 1 hour ago|||
Or just <C-u> in insert mode. <C-u> and <C-w> are standard Vim insert mode commands.

https://vimhelp.org/insert.txt.html#i_CTRL-U

ahmedfromtunis 6 hours ago|||
The vim version is much easier, if you ask me: 3 strokes, 2 keys and 0 combinations.

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".

ratrocket 5 hours ago|||
Maybe I have my bash/readline vi mode configured specially to do this, but if I want to delete the entire line and type a new one (from anywhere in that line), I do something simpler than either of these alternatives:

<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...]

maleldil 5 hours ago|||
<c-o>S is also a vim sequence. The equivalent readline/emacs is <c-e><c-u> or <c-a><c-k>, or just <c-u> or <c-k> if you're already at the end/start of the line.
nidnogg 5 hours ago|||
I've been a vim/nvim casual user for the past year or two, and I still feel as if I'm slightly less proficient in it for the amount of time that I put into it.

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.

exceptione 8 hours ago|||

   <esc>3bcw
What is your keyboard layout? This looks like a crime against humanity on a regular qwerty kb.
lenkite 37 minutes ago|||
Remap Capslock to Esc. Possible in every OS now.
ahmedfromtunis 5 hours ago||||
I use qwerty and azerty, and in both I never felt typing the sequence was any harder than typing any other regular word. Generally speaking, I prefer sequential "shortcuts" then multikey bindings.
sva_ 8 hours ago|||
Instead of esc, type ctrl [
exceptione 8 hours ago||
Does it help a lot? You've still got a three to type which is a crime, plus some letters, only to move 3 words. My typing skills are not great, but that sounds like an awful lot of work(?)

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?

roxolotl 6 hours ago|||
I think it’s a difference in how people think. I can’t remember hotkeys. It just doesn’t compute. But with vim style bindings it’s much closer to writing a sentence. `3`, number of times, `b`, beginning of word, `c`, change, `w`, word. Yea it’s a lot. I cannot explain why it’s simpler for me to learn that than emacs style bindings but it is.
helterskelter 1 hour ago||
Obligatory:

Your Problem with vim is you don't grok vi

https://stackoverflow.com/questions/1218390/what-is-your-mos...

gsinclair 8 hours ago||||
I don’t love vi-mode, but I’ll address your comment.

Many 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.

sva_ 3 hours ago|||
We're basically playing a game: if you have to leave homerow hand position, you've lost
ruptwelve 6 hours ago||
The <esc>v has been such a lifesaver at times when having to execute/modify super complex commands!
MattGrommes 31 minutes ago||
If only somebody had a lifehack for making me remember all these awesome commands.

If I do something the slow way it's usually because I don't do the operation enough to burn it into my memory, or I got burned by accidentally hitting something close but incorrect once and closed the tab or something.

w-ll 29 minutes ago||
post-it note until you dont need it anymore
shigawire 24 minutes ago||
I hate to be the AI guy, but a coach that lived in my terminal and corrected me when I do it the slow way would actually help.
tkocmathla 10 hours ago||
I love this, from a comment on the article:

  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
  ```
rgrau 9 hours ago||
A similar trick:

    #!/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.
mzs 2 hours ago|||
Wow I hate* that. I use bracket comments. They're cool cause they are bracket comments, so I use it in scripts to document pipelines. They are annoying cause they are bracket comments, in an interactive shell I have to type more and in TWO places. It's fun to reason-out how it works ;)

  $ 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 that
rgrau 1 hour ago||
for multiline pipes, it's WAY better to format like

    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

mzs 18 minutes ago||
You'll probably dislike this too:

  $ {
  >     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!}
  baz
internet_points 9 hours ago|||
Yes! That one's going in my $PATH. Such a useful use of cat!
000ooo000 8 hours ago||
What does it provide over

mycmd1 #| mycmd2

chriswarbo 7 hours ago||
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
mkoryak 6 hours ago||
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

chriswarbo 6 hours ago|||
Pipelines are usually built up step by step: we run some vague, general thing (e.g. a `find` command); the output looks sort of right, but needs to be narrowed down or processed further, so we press Up to get the previous command back, and add a pipe to the end. We run that, then add something else; and so on.

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 :-)

agons 6 hours ago|||
I can imagine a pipeline where intermediate stages have been inserted to have some side effect, like debug logging all data passing through.
fellerts 10 hours ago||
CTRL + W usually deletes everything until the previous whitespace, so it would delete the whole '/var/log/nginx/' string in OP's example. Alt + backspace usually deletes until it encounters a non-alphanumeric character.

Be careful working CTRL + W into muscle memory though, I've lost count of how many browser tabs I've closed by accident...

hejira 10 hours ago||
In my terminal it's the exact opposite – Alt-Backspace deletes to the previous space, whereas Ctrl-W deletes to the last non-alphanumeric (such as /). I'm using fish shell in an Alacritty terminal.

Yeah, pressing Ctrl-W accidentially is a pain sometimes ... but Ctrl-Shift-T in Firefox is a godsend.

Aerolfos 9 hours ago||
> Yeah, pressing Ctrl-W accidentially is a pain sometimes ... but Ctrl-Shift-T in Firefox is a godsend.

Fun 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.

dgrunwald 7 hours ago||
It's a normal command called "View: Reopen Closed Editor".
oxag3n 1 hour ago|||
Depends on the shell - bash on my Ubuntu deletes entire '/var/log/nginx/', while after switching to sh it deletes only nginx
fainpul 9 hours ago|||
Set $WORDCHARS accordingly. In your case, remove / from $WORDCHARS.

https://unix.stackexchange.com/a/726014

exceptione 8 hours ago||
For the bash people

  stty werase undef
  bind '"\C-w": backward-kill-word'

source: https://superuser.com/questions/212446/binding-backward-kill...
gryfft 10 hours ago|||
Ctrl-Shift-T usually brings that tab right back at least
figmert 9 hours ago|||
> Be careful working CTRL + W into muscle memory though, I've lost count of how many browser tabs I've closed by accident...

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.

fp64 3 hours ago|||
I've installed "More Better Ctrl-W" for Chromium, and mapped Ctrl-W to do nothing, and Ctrl-D to close the current tab
arcanemachiner 47 minutes ago||
But how am I supposed to create or edit a bookmark?
themafia 1 hour ago|||
'man readline' contains all the useful key combinations.
sfink 3 hours ago||
...which is why I recently went to about:keyboard and removed that hotkey. I love that page.

That, and Ctrl-N. No more forest of blank browser windows when using a terminal emulator in a web page!

(Firefox only)

olejorgenb 1 hour ago||
Do yourself a favor and upgrade your history search with fzf shell integration (or similar): https://youtu.be/u-qLj4YBry0?t=223 / https://junegunn.github.io/fzf/shell-integration/
hikarudo 9 hours ago||
One trick I use all the time:

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

idoubtit 15 minutes ago||
You missed an easier alternative that was in the article: ctrl-u saves and clears the current line, then you can input new commands, then use ctrl-y to yank the saved command.

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>

gvalkov 6 hours ago|||
In zsh you can bind "push-line-or-edit". In bash and all readline programs, you can approximate it with C-u followed by C-y (i.e. cut and paste). My history is still full of '#' and ':' (csh trauma) prefixed command-lines like you described though ...
fragmede 9 hours ago||
Fwiw, in Bash, alt-shift-3 will prepend the current command with # and start a new command.
j4cobgarby 8 hours ago||
More generally, it's alt-#. On an ISO (e.g. UK) keyboard layout, shift-3 isn't a hash.
kleiba 3 hours ago||
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.
cipritom 2 hours ago|
you should look into autojump which has `jc` (jump child), or other similar flavours of "smart cd" (z, fzf, etc)
kleiba 1 hour ago||
Thanks, but I like that this is just a small, simple bash function without the need to install 3rd-party software.
gchamonlive 2 hours ago|
For me the ultimate trick is to open the current prompt in vim with F2 (Ctrl+X ctrl+E seems to work too):

  # 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 f2
More comments...