Closed Freed-Wu closed 1 year ago
Exactly what i needed right now. Although imo it's not trans' job to do it. Here's what I use
#!/bin/bash
echo "" | xclip -sel clip
cpbrd=$(xclip -sel clip -o 2> /dev/null)
while :
do
sleep 1
newcpbrd=$(xclip -sel clip -o 2> /dev/null)
if [[ "$cpbrd" != "$newcpbrd" ]]; then
cpbrd=$newcpbrd
printf "DE: $cpbrd\n"
printf "EN: "
trans -s "de" -t "en" -b "$cpbrd"
printf "\n"
fi
done
More clippers can be found https://github.com/felixonmars/ydcv/pull/71/files
And I hope it is multi process, that is after trans -I
, I can input anything to translate, and trans check clipboard's change to translate it in the same time. Like https://github.com/felixonmars/ydcv/issues/66
Share my script:
#!/usr/bin/env bash
cpbrd="$(xsel -o | perl -0pe 's/-\n//g;s/\n/ /g;s/^ | $//g')"
while :
do
newcpbrd="$(xsel -o | perl -0pe 's/-\n//g;s/\n/ /g;s/^ | $//g')"
if [[ "$cpbrd" != "$newcpbrd" ]]; then
cpbrd=$newcpbrd
trans "$cpbrd"
fi
done
I realize one alternative for myself. Support translate clipboard, shell completion, etc. So I close this issue now.
Such as watch when
xsel -ob
's result has changed, translate it and print to stdout.Thanks!