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...
Shell Tricks That Make Life Easier (and Save Your Sanity)
191–200 of 287 posts
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#192Just 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…
you should look into autojump which has `jc` (jump child), or other similar flavours of "smart cd" (z, fzf, etc)
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#193Using 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.
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.
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.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#194Maybe not a shell trick per-se but I have been a very big fan of zoxide. It can jump around your common directories. If you have a ~/workspace/projects and you are anywhere and type `cd projects` it will take you to that directory. I never realized how much I got hooked onto it, until I used a system without it.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#195Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#196Not a fan of the LLM-flavoured headings, and the tips seem like a real mixed bag (and it'd be nice to give credit specifically to the readline library where appropriate as opposed to the shell), but there are definitely a few things in here I'll have to play around with. 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…
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#197Here's my favorite tip: If you use bash, you can write bash on your prompt (duh). But this is one of the biggest reasons I stick with bash everywhere, as I am quite comfortable and experienced in bash and sometimes it's just easier to write things like `for i in *.mp3; do ffmpeg -i $i ...` etc. If it's re-usable, I write it to a bash script later.
That's vaccously true as you said isn't it? I write fish on my shell and then I can save it as a fish script. Worth noting that bash is much more portable and available by default, but if I'm going for portability I go straight to /bin/sh
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#198CTRL + 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...
I've installed "More Better Ctrl-W" for Chromium, and mapped Ctrl-W to do nothing, and Ctrl-D to close the current tab
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#199Earlier 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.
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
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#200Using 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.
3bcw What is your keyboard layout? This looks like a crime against humanity on a regular qwerty kb.