External Publication
Visit Post

It’s surprisingly hard to reliably paste the current date at the cursor on Linux

The Autodidacts February 25, 2026
Source

Long, long ago, in a dotfiles directory far away, I had this snippet:

bindsym control+semicolon exec date '+%Y-%m-%d' | tr -d "\n" | xsel -i -b && xdotool sleep 0.5 key "ctrl+v"

Isn’t it a beauty?

But it worked, in i3 on X11.

I devoted 500 words to bemoaning how hard it was to port this over to Wayland + Sway. The section was titled More Fun with Segmentation Faults, and my “solution” involved building alpha-quality software from source, and accepting an 80/20 solution.

And then I migrated to a boring version of Linux: Xfce (and later Cinnamon) on Linux Mint. Even though I was on X again, for some reason my original snippet no longer worked 😭.

I ended up running AutoKey 24/7 just so I could have this snippet. And it didn’t even work reliably.

Further reading: Save the Date .

Paste didn’t work in my terminal emulator, and I spend most of my time in Helix text editor, in Fish Shell, running in a Tmux session, in Ghostty (I know, I insist on making things difficult for myself).

I set it to fill the clipboard with the current date so that I could paste it, but I often ended up having something important already on the clipboard when I ran the shortcut, and overwriting it.

So today I made a small improvement. It tries to input the date directly with send_keys. But it also temporarily puts the date on the clipboard. Before it puts the date on the clipboard, it backs-up whatever was on the clipboard. Then, after one second has elapsed, it restores the clipboard to its original state.

So if I’m in Helix, I hit Ctrl+; Ctrl+Shift+V (which is only as many keystrokes as typing 2026-, so we are saving ourselves five whole keypresses here! And that’s assuming I know what the date is in the first place, which I usually don’t.)

Otherwise, it’s Ctrl+; and done.

Here’s my current AutoKey script:

import time
output = system.exec_command("date -I") # ISO 8601 YYYY-MM-DD format
oldtext = clipboard.get_clipboard() # backup what's on the clipboard
clipboard.fill_clipboard(output) # put date on clipboard
keyboard.send_keys("<ctrl>+V") # paste date
time.sleep(1) # give user chance to paste if send_keys failed
clipboard.fill_clipboard(oldtext) # restore previous clipboard content

It still isn’t perfect, but it’s almost good enough.

Discussion in the ATmosphere

Loading comments...