Often I find myself partway through writing a long command (or chain of commands) and realise I need to run another command before I can finish typing out this current one.
Examples
Sometimes, I...
- Need to find the exact name of a network interface (
wlp2s0b1
-- blargh); - Need to check the documentation of a command;
- Need to start a daemon (with
systemctl
,service
, etc) before I can communicate with it; - Need to
sudo ls
a directory if I'm performing a command with sudo and tab-completion isn't working because I don't have permission in the directory I'm operating in.
I guess the ideal solution for me would be a keyboard shortcut that pushes my current command to a stack and empties the line, and another command that pops the top command from that stack into the input line.
Kinda-sorta-solutions that I currently use:
- Use my mouse to select the command in the terminal (if I even have a graphical terminal available) and copy it, pasting when ready (slow);
- Press enter (hoping that the command just fails than deleting things) and use ↑ to get back up to it (dangerous);
- Type it out again (time-consuming)
Any suggestions for how I could better accomplish this? I use zsh
where I can, but a solution that works on bash
as well would be appreciated.
zsh
too. In any POSIX shell you can do the same invi
mode with ESC-#. Another possibility is to the shell's kill-buffer if it offers one - CTRL+U will usually cut from cursor to head of line, CTRL+K from cursor to end, and CTRL+W from cursor back one word.zsh
andbash
at least save cuts like that in a kill-ring - so you can paste it back in later (several commands later if wanted) with CTRL+Y. – mikeserv Mar 23 '15 at 05:47zsh
's line-editor will cuts to newline boundaries - so I can edit commands in pieces on the command-line cutting one or two lines out of one history command, pasting it into a new one, scrolling back to find a different command, cutting out of it, then forward again to paste in some more. It's almost the only reason I usezsh
. – mikeserv Mar 23 '15 at 05:59