Просмотр исходного кода

Add command/clipboard based xtrans() and xfromc()

Alois Mahdal 8 месяцев назад
Родитель
Сommit
b1fab65a91
1 измененных файлов: 36 добавлений и 0 удалений
  1. 36
    0
      dotfiles/config/bashum/main.bashrc

+ 36
- 0
dotfiles/config/bashum/main.bashrc Просмотреть файл

@@ -633,6 +633,42 @@ xcxx() {
633 633
     return "${PIPESTATUS[1]}"
634 634
 }
635 635
 
636
+xtrans() {
637
+    #
638
+    # Translate text in primary clipboard using code $1 and output it
639
+    #
640
+    # Similar to xcxx but assumes code snippet, and prints the result
641
+    # to make it easier to check it visually.
642
+    #
643
+    local code=$1
644
+    test $# -gt 1 && code=$(printf '%q ' "$@")
645
+#   echo >&2 "debug:code=$code"
646
+    local es
647
+    xop o | bash -c "$code" | xop ii
648
+    es="${PIPESTATUS[1]}"
649
+    xop oo >&2
650
+    echo >&2
651
+    return "$es"
652
+}
653
+
654
+xfromc() {
655
+    #
656
+    # Get text using code $1 and output it
657
+    #
658
+    # Similar to xtrans but assumes code snippet, and prints the result
659
+    # to make it easier to check it visually.
660
+    #
661
+    local code=$1
662
+    test $# -gt 1 && code=$(printf '%q ' "$@")
663
+    echo >&2 "debug:code=$code"
664
+    local es
665
+    bash -c "$code" | xop ii
666
+    es="${PIPESTATUS[0]}"
667
+    xop oo >&2
668
+    echo >&2
669
+    return "$es"
670
+}
671
+
636 672
 vx() {
637 673
     #
638 674
     # Edit stdin and save it to primary clipboard