This is a fancy thing that iTerm can do, somewhat invasively, and Terminal.app can do, somewhat transparently, and if you already know how to do this

Quickly copy the output of the last shell command you ran

submited by
Style Pass
2021-05-22 17:30:01

This is a fancy thing that iTerm can do, somewhat invasively, and Terminal.app can do, somewhat transparently, and if you already know how to do this then just keep doing your thing and don’t worry about it.

This post is going to show you how to do it in tmux, because tmux is great and it’s not coupled to your choice of terminal emulator and it’s a cool superpower to add to your toolkit.

But it’s not trivial to do in tmux. It took me a while to figure it out. Which is why you’re looking at a blog post, and not a code snippet.

But my goodness. That’s a lot. That’s a hot mess. And it’s pretty coupled to my particular prompt, which looks like this:

Your prompt probably doesn’t look like that. It’s probably full of fancy git statuses and branch names and all kinds of things. That’s okay; this approach should work anyway. You just need to modify it to suit your particular prompt.

It’s important because, without it, tmux will trim the trailing space from the output line when it puts it in scrollback, which means that if you ever hit enter without typing a command:

Leave a Comment