From f0ec5c69f656c6d6d0a75465b767a5ba6968ed78 Mon Sep 17 00:00:00 2001 From: fluks Date: Wed, 13 Oct 2021 00:35:31 +0300 Subject: [PATCH 1/2] Add bash completion --- translate-shell | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 translate-shell diff --git a/translate-shell b/translate-shell new file mode 100644 index 00000000..cb90b206 --- /dev/null +++ b/translate-shell @@ -0,0 +1,20 @@ +_translate() { + COMPREPLY=() + cur=`_get_cword` + + if [ $COMP_CWORD -eq 1 ]; then + COMPREPLY=($(compgen -W "$(trans -help \ + | awk '{ gsub(/\x1b\[([0-9]{1,3}(;[0-9]{1,2})?)?m/, ""); print }' \ + | awk '{\ + for (i = 1; i <= NF; i++) {\ + if (index($i, "-") == 1) {\ + sub(/[,\.]$/, "", $i);\ + print $i\ + }\ + }\ + }')" -- "$cur")) + fi + + return 0 +} && +complete -F _translate default trans From 66e3d37ac938b861491883b6d844306de078a3b1 Mon Sep 17 00:00:00 2001 From: fluks Date: Wed, 13 Oct 2021 11:33:46 +0300 Subject: [PATCH 2/2] Drop colors using -no-ansi option --- translate-shell | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/translate-shell b/translate-shell index cb90b206..ca704981 100644 --- a/translate-shell +++ b/translate-shell @@ -3,8 +3,7 @@ _translate() { cur=`_get_cword` if [ $COMP_CWORD -eq 1 ]; then - COMPREPLY=($(compgen -W "$(trans -help \ - | awk '{ gsub(/\x1b\[([0-9]{1,3}(;[0-9]{1,2})?)?m/, ""); print }' \ + COMPREPLY=($(compgen -W "$(trans -help -no-ansi \ | awk '{\ for (i = 1; i <= NF; i++) {\ if (index($i, "-") == 1) {\