My AI assistant suggests commit messages. For a while I copied each one out of the terminal by hand, selecting the text with the mouse and pasting it into my git client. It works, but selecting text in the terminal drags the line breaks along with it. The terminal wraps the text to fit its width, and those wraps come through as real line breaks in whatever you paste into. Then you have to clean them out.
The fix is one shell command. On macOS there is pbcopy. Pipe any text into it and the text
lands on the clipboard:
printf '%s' 'Fix off-by-one in the date parser' | pbcopy
So I told the assistant to use it whenever it proposes a commit message. It writes the message and sends
it through pbcopy in the same step. By the time I have read the suggestion, it is already on
the clipboard. I switch to my git client and paste. The text arrives as one clean string, no stray line
breaks to remove.
I put the rule in the project's instructions file so I don't have to ask for it every time. The assistant reads that file at the start of a session and remembers to copy the message along with proposing it.
The trick is not limited to commit messages. Any short string you are going to paste somewhere else works
the same way. I use it a lot when iterating over SQL. The assistant suggests a query, puts it on the
clipboard, and I paste it straight into my database client to run it. If it isn't right, I describe the
change and get the next version the same way. It works just as well for a curl command I want
to try against a running service, or a few lines I want to paste into Slack for a colleague. If the next
thing you do with the text is paste it, ask for it on the clipboard instead of leaving it in the
scrollback.
If you are on Linux, the same thing is xclip -selection clipboard, or wl-copy if
you are on Wayland. Windows has an equivalent too, I am sure, but I haven't touched a Windows box in
fifteen years, so I won't pretend to know what it is.
Resources
- An AI Coding Assistant as a Force Multiplier - more on working with an assistant day to day
- Thomas Sundberg - the author