1

(I am using the kitty terminal emulator, though I would appreciate answers for other terminal emulators as well.)

I run a command, and get some error message, like this:

~ » somecommand
❌️ Some Error Message  # from stderr

Obviously, to copy the stderr of the command, I can do somecommand 2>&1 >/dev/null | wl-copy (or xclip)
But I usually forget to do that, and I don't want to re-run the command, and I never remember the syntax for piping stderr so I have to context-switch anyway to look it up.

Is there a simple command I can alias in my .zshrc, or a keyboard shortcut I can configure, to copy the stderr of the previous run command in the terminal emulator?

1 Answer 1

-1

This is something that works in bash, not sure about other shells.
You can redirect your stderr globally into tee which will "split" it writing it both to a file and the terminal:

$ exec 2> >(tee ~/tmp/error.log)

(can add this command to you .bashrc or similar).
However, the caveat is that the shell prompt and command echo in bash are written to stderr, so you are going to see a lot of noise in the log file (including escape codes for colors and such).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.