,translate-shell.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # Coding: utf-8
  3. # Editor: kate
  4. # Created 2022-01-30
  5. #_sudo_apt_install_ xclip
  6. #_sudo_dpkg_i_ translate-shell_0.9.6.12-1_all.deb https://pkgs.org/download/translate-shell
  7. source $HOME/.SCR/lib.sh
  8. echo ""
  9. if [ $# == "0" ]
  10. then
  11. arg=$(xclip -selection clipboard -o)
  12. echo "From clipboard: $arg"
  13. else
  14. arg="$@"
  15. echo "From command line: $@"
  16. fi
  17. if [ "1" == "$(echo "$arg" | wc -w)" ] # добавляем кавычка в зависимости от фраза это или слово.
  18. then
  19. text="$arg"
  20. echo "Word: $text"
  21. else
  22. text="\"$arg\""
  23. echo "Phrase: $text"
  24. fi
  25. echo ""
  26. echo "Select option for translate:"
  27. echo ""
  28. echo "[1] Translate to russian. Short format"
  29. echo "[2] Translate to english. Short format"
  30. echo "[3] Translate to qazaq. Short format"
  31. echo "[4] Translate to russian"
  32. echo "[5] Translate to english"
  33. echo "[6] Translate to qazaq"
  34. echo ""
  35. read num_choice
  36. case "$num_choice" in
  37. "1" ) result="$(trans -b -no-auto :ru "$text")" ;;
  38. "2" ) result="$(trans -b -no-auto :en "$text")" ;;
  39. "3" ) result="$(trans -b -no-auto :kk "$text")" ;;
  40. "4" ) result="$(trans -no-auto :ru "$text")" ;;
  41. "5" ) result="$(trans -no-auto :en "$text")" ;;
  42. "6" ) result="$(trans -no-auto :kk "$text")" ;;
  43. * ) fun_echo_stadia 11 0 "This item does not exist"
  44. exit ;;
  45. esac
  46. echo "$result"
  47. echo ""
  48. echo "If you need copy translate to clipboard press 1 and Enter"
  49. echo "Any other and Enter for exit"
  50. echo ""
  51. read num_choice_2
  52. case "$num_choice_2" in
  53. "1" ) echo "$result" | sed 's/\x1b\[[0-9;]*m//g' | xclip -selection c ;;
  54. # удаление escape-последовательностей ANSI и вывод в буфер обмена
  55. * ) exit ;;
  56. esac