Upload files to ".local/bin"

This commit is contained in:
coast 2025-05-29 23:15:07 +02:00
parent d17e02fa0f
commit 3e0eaaf829
2 changed files with 102 additions and 0 deletions

48
.local/bin/cslate Normal file
View file

@ -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

54
.local/bin/ecop Normal file
View file

@ -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