Skip to content

Instantly share code, notes, and snippets.

@suside
Created November 18, 2025 08:44
Show Gist options
  • Select an option

  • Save suside/ae013705d2236879f1eb15e2d37aed0f to your computer and use it in GitHub Desktop.

Select an option

Save suside/ae013705d2236879f1eb15e2d37aed0f to your computer and use it in GitHub Desktop.
Migrate gpaste to copyq
#!/usr/bin/env python3
"""
Migrate GPaste history to CopyQ.
Reads GPaste history format (UUID: content with multiline support)
and imports each entry into CopyQ using its CLI.
"""
import subprocess
import re
import sys
def parse_gpaste_history(filename):
"""Parse GPaste history file and return list of clipboard entries."""
entries = []
current_entry = None
with open(filename, 'r', encoding='utf-8') as f:
for line in f:
# Check if line starts with a UUID pattern
uuid_match = re.match(r'^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}):\s*(.*)', line)
if uuid_match:
# Save previous entry if exists
if current_entry is not None:
entries.append(current_entry.rstrip('\n'))
# Start new entry with content after UUID
current_entry = uuid_match.group(2)
if current_entry:
current_entry += '\n'
else:
current_entry = ''
else:
# Continuation of previous entry (multiline content)
if current_entry is not None:
current_entry += line
# Don't forget the last entry
if current_entry is not None:
entries.append(current_entry.rstrip('\n'))
return entries
def import_to_copyq(entries):
"""Import entries to CopyQ using its CLI."""
print(f"Importing {len(entries)} entries to CopyQ...")
# Import in reverse order so the oldest items end up at the bottom
for i, entry in enumerate(reversed(entries)):
try:
# Use copyq add command to add text to clipboard history
subprocess.run(
['copyq', 'add', entry],
check=True,
capture_output=True,
text=True
)
print(f"Imported entry {i+1}/{len(entries)}")
except subprocess.CalledProcessError as e:
print(f"Error importing entry {i+1}: {e}", file=sys.stderr)
print(f"Entry content: {entry[:100]}...", file=sys.stderr)
except FileNotFoundError:
print("Error: copyq command not found. Please install CopyQ first.", file=sys.stderr)
sys.exit(1)
print("Migration complete!")
def main():
if len(sys.argv) < 2:
print("Usage: python migrate_gpaste_to_copyq.py <gpaste_history_file>")
sys.exit(1)
history_file = sys.argv[1]
print(f"Reading GPaste history from: {history_file}")
entries = parse_gpaste_history(history_file)
print(f"Found {len(entries)} clipboard entries")
import_to_copyq(entries)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment