Skip to content

Instantly share code, notes, and snippets.

@santiagocasas
Created June 26, 2026 10:38
Show Gist options
  • Select an option

  • Save santiagocasas/2e049b4d7b8f8c14234e2a03b6789932 to your computer and use it in GitHub Desktop.

Select an option

Save santiagocasas/2e049b4d7b8f8c14234e2a03b6789932 to your computer and use it in GitHub Desktop.
Xclip copy string in clipboard, strip spaces, copy back
#!/usr/bin/env bash
set -euo pipefail
if ! command -v xclip >/dev/null 2>&1; then
printf 'stripcopy: xclip is not installed or not in PATH\n' >&2
exit 1
fi
cleaned=$(xclip -selection clipboard -o | python3 -c 'import sys; print("".join(sys.stdin.read().split()), end="")')
printf '%s\n' "$cleaned"
printf '%s' "$cleaned" | xclip -selection clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment