Created
December 7, 2021 16:45
-
-
Save nat-418/ff9f2d8ac304956cab1fab1766663eca to your computer and use it in GitHub Desktop.
Wrapper script for Argos Translate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env tclsh | |
# language should be a two-character ISO code | |
# languages must be installed using Argos GUI | |
set language_codes { | |
ar de en es fr it zh | |
} | |
# CLI takes two arguments, ignore the rest | |
lassign $argv from_code to_code | |
if {$from_code ni $language_codes} { | |
puts stderr "Error: $from_code is not a valid language code." | |
puts stderr "The following languages are supported: $language_codes" | |
exit 1 | |
} | |
if {$to_code ni $language_codes} { | |
puts stderr "Error: $from_code is not a valid language code." | |
puts stderr "The following languages are supported: $language_codes" | |
exit 1 | |
} | |
puts -nonewline "$from_code: " | |
flush stdout | |
gets stdin input | |
# https://github.com/argosopentech/argos-translate | |
set translate "argos-translate --from-lang $from_code --to-lang $to_code" | |
# https://github.com/astrand/xclip | |
set copy "xclip -filter -selection clipboard" | |
set output [exec sh -c "$translate '$input' | $copy"] | |
puts -nonewline "$to_code: " | |
flush stdout | |
puts $output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment