aboutsummaryrefslogtreecommitdiff
path: root/local
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2024-09-28 21:10:11 +0200
committerCharles Cabergs <me@cacharle.xyz>2024-09-28 21:10:11 +0200
commitafc33e0e043f28bc1678c27e875c4c84ffef83bd (patch)
tree4982a261cabeb76c17364b8391d2d5ddd774f260 /local
parent22049ae6f988b143f74d7e022589222b3b060141 (diff)
downloaddotfiles-afc33e0e043f28bc1678c27e875c4c84ffef83bd.tar.gz
dotfiles-afc33e0e043f28bc1678c27e875c4c84ffef83bd.tar.bz2
dotfiles-afc33e0e043f28bc1678c27e875c4c84ffef83bd.zip
Add translate-prompt script
Diffstat (limited to 'local')
-rwxr-xr-xlocal/bin/translate-prompt40
1 files changed, 40 insertions, 0 deletions
diff --git a/local/bin/translate-prompt b/local/bin/translate-prompt
new file mode 100755
index 0000000..9419f2a
--- /dev/null
+++ b/local/bin/translate-prompt
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+command -v trans > /dev/null ||
+ { echo "translate-shell not installed" ; exit 1 ; }
+command -v rofi > /dev/null &&
+ menu_exec='rofi -dmenu' ||
+ menu_exec='dmenu'
+
+choice="$(
+$menu_exec <<EOF
+From Clipboard
+Open Editor
+EOF
+)"
+
+# TODO: alacritty --class CustomFloating when I figure out how to center floating windows
+
+text_file="$(mktemp /tmp/translate_prompt_text_XXXXXX)"
+
+case "$choice" in
+ 'From Clipboard')
+ xclip -out -selection clipboard > "$text_file"
+ ;;
+ 'Open Editor')
+ text_file="$(mktemp /tmp/translate_prompt_text_XXXXXX)"
+ "$TERMINAL" -e "$EDITOR" "$text_file"
+ ;;
+ *)
+ echo -n "$choice" > "$text_file"
+ ;;
+esac
+
+brief=-brief
+if [ "$(head -c1 "$text_file")" = '#' ]
+then
+ brief=''
+ sed -i '1 s/^#//' "$text_file"
+fi
+
+"$TERMINAL" -e trans $brief -view -input "$text_file"