From 3e0eaaf829dd16901b3510146227b4191e8a905f Mon Sep 17 00:00:00 2001 From: coast Date: Thu, 29 May 2025 23:15:07 +0200 Subject: [PATCH] Upload files to ".local/bin" --- .local/bin/cslate | 48 +++++++++++++++++++++++++++++++++++++++++ .local/bin/ecop | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .local/bin/cslate create mode 100644 .local/bin/ecop diff --git a/.local/bin/cslate b/.local/bin/cslate new file mode 100644 index 0000000..86e9304 --- /dev/null +++ b/.local/bin/cslate @@ -0,0 +1,48 @@ +#!/bin/sh + +translate() { + text="$1" + lang="$2" + + case "$lang" in + persian|fa|per) lang="fa" ;; + german|de|ger) lang="de" ;; + french|fr|fre) lang="fr" ;; + spanish|es|spa) lang="es" ;; + *) lang="$lang" ;; + esac + + if command -v jq >/dev/null 2>&1; then + translated=$(curl -s "https://libretranslate.de/translate" \ + -d "q=$text" -d "source=auto" -d "target=$lang" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + | jq -r '.translatedText') + else + translated=$(curl -s "https://libretranslate.de/translate" \ + -d "q=$text" -d "source=auto" -d "target=$lang" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + | sed -n 's/.*"translatedText":"\([^"]*\)".*/\1/p') + fi + + printf "\033[1;34mOriginal:\033[0m %s\n" "$text" + printf "\033[1;33mTranslation (%s):\033[0m %s\n" "$lang" "$translated" +} + +if ! command -v curl >/dev/null 2>&1; then + echo "Error: curl is required" >&2 + exit 1 +fi + +case "$1" in + -w|--word|-s|--sentence) + [ -z "$3" ] && { echo "Usage: $0 [-w|-s] TEXT LANGUAGE" >&2; exit 1; } + translate "$2" "$3" + ;; + *) + echo "Usage: $0 [-w|-s] TEXT LANGUAGE" >&2 + echo " -w, --word Translate a word" >&2 + echo " -s, --sentence Translate a sentence" >&2 + echo "Example: $0 -w hello persian" >&2 + exit 1 + ;; +esac \ No newline at end of file diff --git a/.local/bin/ecop b/.local/bin/ecop new file mode 100644 index 0000000..82cee29 --- /dev/null +++ b/.local/bin/ecop @@ -0,0 +1,54 @@ +#!/usr/bin/env lua + +local args = {...} +local tmpfile = os.tmpname() +local cmd = table.concat(args, " ") + +-- run the command and write its output to tmpfile +local ok = false +local output = "" + +do + local f = io.popen(cmd, "r") + if f then + output = f:read("*a") + f:close() + + local outFile = io.open(tmpfile, "w") + if outFile then + outFile:write(output) + outFile:close() + end + + ok = true + end +end + +if ok then + local session = os.getenv("XDG_SESSION_TYPE") + if session == "wayland" then + local f = io.popen("wl-copy", "w") + if f then + f:write(output) + f:close() + end + elseif session == "x11" then + local f = io.popen("xclip -selection clipboard", "w") + if f then + f:write(output) + f:close() + end + else + io.stderr:write("UNKNOWN SESSION TYPE!! >> " .. tostring(session) .. "\n") + os.remove(tmpfile) + os.exit(1) + end + + print(output) + os.remove(tmpfile) + os.exit(0) +else + print(output) + os.remove(tmpfile) + os.exit(1) +end