#!/bin/bash #---------------------------------------------------------------- # translate-wl — Translate selected text using translate-shell # with Wayland clipboard (wl-clipboard) # # Replaces the old ratflow trans-xsel script (X11 xsel-based). # Uses wl-paste to get clipboard content and wl-copy to write # the translation back, plus a notification via notify-send # (which works with mako/swaync on Wayland). # # Usage: # translate-wl en:pl — translate English to Polish # translate-wl pl:en — translate Polish to English # translate-wl de:en — translate German to English, etc. # # Workflow: # 1. Select text (it goes to Wayland primary/clipboard) # 2. Press the bound key (e.g. $mod+t) # 3. Script reads selection via wl-paste, translates, # shows notification, and copies result to clipboard # # Dependencies: translate-shell (trans), wl-clipboard, libnotify #---------------------------------------------------------------- LANG_PAIR="${1:-en:pl}" # Get clipboard content (user should select text first) # wl-paste gets the clipboard content; for primary selection use wl-paste -p TEXT=$(wl-paste -p 2>/dev/null || wl-paste 2>/dev/null) if [ -z "$TEXT" ]; then notify-send -t 3000 "Translation" "No text in clipboard/selection" exit 1 fi # Translate using translate-shell RESULT=$(trans -b "$LANG_PAIR" "$TEXT" 2>/dev/null) if [ -z "$RESULT" ]; then notify-send -t 3000 "Translation" "Translation failed" exit 1 fi # Copy result to clipboard echo -n "$RESULT" | wl-copy # Show notification notify-send -t 5000 "Translation ($LANG_PAIR)" "$RESULT"