Automatically Fixing Smart Quotes on Kubuntu (X11)
May 11, 2026
One of the most annoying problems when copying code or text from the web is the automatic use of smart quotes (also called curly quotes or typographic quotes).
Instead of getting:
"hello"
you end up with:
“hello”
For regular writing this is fine, but for developers it can become a nightmare because many programming languages expect plain ASCII quotes.
Why This Happens
Many modern websites, editors, and rich text systems automatically replace straight quotes with typographic ones.
Examples:
| Type | Character |
|---|---|
| Straight double quote | " |
| Opening smart quote | “ |
| Closing smart quote | ” |
| Straight apostrophe | ' |
| Smart apostrophe | ’ |
This commonly happens when copying from:
- Blogs
- Documentation sites
- AI-generated content
- PDFs
- Microsoft Word
- Google Docs
- CMS editors
- Messaging apps
Even if smart quotes are disabled on your own system, copied web content may still contain them.
Why Developers Hate This
These characters can silently break:
- PHP
- Shell scripts
- SQL
- JSON
- YAML
.envfiles- nginx configs
- JavaScript
Example:
echo “Hello”;
This looks valid at first glance, but PHP will throw an error because “ and ” are not valid string delimiters.
The worst part is that some fonts make them almost indistinguishable from normal quotes.
The Goal
Automatically sanitize clipboard contents system-wide on Kubuntu so that:
“ ”
‘ ’
becomes:
" "
' '
without manually running commands every time.
The Solution
A small background clipboard watcher script.
The script continuously watches the clipboard and automatically replaces smart quotes with plain ASCII quotes whenever new text is copied.
This works especially well on Kubuntu/X11.
Install Required Tools
Install xsel:
sudo apt install xsel
Create the Clipboard Cleaner Script
Create a scripts directory if needed:
mkdir -p ~/Scripts
Create the script:
nano ~/Scripts/clipboard-cleaner.sh
Paste the following:
#!/bin/bash
last=""
while true; do
current=$(xsel --clipboard --output 2>/dev/null)
if [ -n "$current" ] && [ "$current" != "$last" ]; then
cleaned=$(printf '%s' "$current" | \
sed \
-e 's/[“”]/"/g' \
-e "s/[‘’]/'/g")
if [ "$cleaned" != "$current" ]; then
printf '%s' "$cleaned" | xsel --clipboard --input
fi
last="$cleaned"
fi
sleep 0.2
done
Save and exit.
Make the Script Executable
chmod +x ~/Scripts/clipboard-cleaner.sh
Test It
Run the script:
~/Scripts/clipboard-cleaner.sh
Now copy:
“hello” and ‘test’
Paste somewhere.
You should get:
"hello" and 'test'
The Better Approach: Run It Automatically with systemd
Instead of manually launching the script every time, create a user-level systemd service.
This allows the clipboard cleaner to:
- Start automatically at login
- Run silently in the background
- Restart automatically if it crashes
- Behave like a native desktop service
Create the systemd User Service
Create the service directory:
mkdir -p ~/.config/systemd/user
Create the service file:
nano ~/.config/systemd/user/clipboard-cleaner.service
Paste:
[Unit]
Description=Clipboard Smart Quote Cleaner
[Service]
ExecStart=/home/miguelgarcia/Scripts/clipboard-cleaner.sh
Restart=always
RestartSec=1
[Install]
WantedBy=default.target
Replace
/home/miguelgarcia/with your own username/path if needed.
Enable the Service
Reload systemd:
systemctl --user daemon-reload
Enable and start the service:
systemctl --user enable --now clipboard-cleaner.service
Useful Commands
Check service status:
systemctl --user status clipboard-cleaner.service
Stop the service:
systemctl --user stop clipboard-cleaner.service
Start it again:
systemctl --user start clipboard-cleaner.service
Disable automatic startup:
systemctl --user disable clipboard-cleaner.service
Why This Approach Is Nice
This solution works system-wide across:
- Browsers
- PDFs
- AI outputs
- Messaging apps
- Documentation websites
- Rich text editors
without needing to manually clean pasted text.
It becomes especially useful for developers working with:
- PHP
- Symfony
- Bash
- SQL
- JSON
- YAML
- nginx
.envfiles
Future Improvements
The script can easily be expanded to normalize additional problematic Unicode characters.
Examples:
| Problematic Character | Replacement |
|---|---|
— |
-- |
… |
... |
| Non-breaking spaces | Normal spaces |
| Zero-width spaces | Removed |
Example additions:
-e 's/—/--/g' \
-e 's/…/.../g'
Final Thoughts
Modern websites increasingly inject invisible Unicode formatting into copied text.
For developers, this can lead to:
- Broken scripts
- Invalid configuration files
- Hard-to-debug syntax errors
- Random parsing failures
This clipboard cleaner creates a safer development workflow by automatically normalizing copied text into clean ASCII characters before pasting.