t() { # Translate to english or chinese value=$1 if [ -z "$value" ]; then value=$(pbpaste) fi
if [ -z "$value" ]; then echo"請輸入要翻譯的內容" return fi echo"$value" if [[ $value =~ [\p{Han}] ]]; then # 進行OpenAI翻譯,並把結果儲存到剪貼簿 sgpt "Translate to chinese: $value" | pbcopy else sgpt "Translate to english: $value" | pbcopy fi
value=$(pbpaste) echo"$value" }
tj() { # Translate to japanese value=$1 if [ -z "$value" ]; then value=$(pbpaste) fi
if [ -z "$value" ]; then echo"請輸入要翻譯的內容" return fi
echo"$value" sgpt "Translate to japanese: $value" | pbcopy