TIL - Fix hanging kitty when using atotto/clipboard golang package
When using Go's popular atotto/clipboard package in Kitty terminal, the terminal would occasionally hang. This happens because the package defaults to xclip on Linux systems, which stays running in the background by design to serve clipboard content to other X applications.
The Fix
Simply remove xclip:
sudo apt remove xclip
The atotto/clipboard package will then fallback to xsel, which doesn't exhibit the same hanging behavior. Looking at the package's source code, it tries clipboard utilities in this order on Linux:
- Wayland:
wl-copy/wl-paste(ifWAYLAND_DISPLAYis set) - X11:
xclip - X11:
xsel - Termux:
termux-clipboard-get/set
Why This Works
By removing xclip, we force the package to use xsel, which has better terminal behavior while providing the same functionality. This is a clean solution that doesn't require any code changes in your Go applications.
Tags: #golang #terminal #linux #debugging