Sep 5, 2020

Tmux to the Rescue

Well, not for free. But today I wanted to copy some text from my tmux session to the clipboard of my machine, which unfortunately didn't work. From what I learned, the clipboard of tmux is simply separate from the system clipboard. But. There is this nice command one can run called tmux show-buffer, which outputs the current clipboard of tmux. Working on my mac, I could combine this with the pbcopy command that I can use to copy things from the terminal to the clipboard.

In the end I added this to my .tmux.conf:

bind y run-shell "tmux show-buffer | pbcopy" \; display-message "Copied tmux buffer to system clipboard"

What one needs to do is first to make sure that one has copied the desired content into the tmux clipboard. In my configuration I have some vim adaptions, so I simply enter visual mode, mark the text I want and click y. Then I click C-b + y to perform the command I have configured above. This puts the text into the clipboard..

Another trick I did today was to extract values from the SSM (Systems Manager) in AWS. You can have parameters stored in there, and a way to extract them is to make sure that you are logged in with the right account in your terminal and then run:

aws --region eu-west-1 ssm get-parameter --with-decryption --name "key-name" | jq -r '.Parameter.Value' | pbcopy

Code of the Day

The get parameter ended up in a very rudimentary script:

aws --region eu-west-1 ssm get-parameter --with-decryption --name "$1" | jq -r '.Parameter.Value' | pbcopy

echo "Parameter value for $1 has been copied to clipboard."