瀏覽代碼

Add xt() and xtt() for typing clipboard out with xdotool

Useful in places where keyboard shortcut is not available, such as
primary clipboard in in almost all GUI applications.
Alois Mahdal 8 月之前
父節點
當前提交
6bd87b80de
共有 2 個檔案被更改,包括 72 行新增0 行删除
  1. 23
    0
      dotfiles/config/bashum/main.bashrc
  2. 49
    0
      dotfiles/config/i3/macros/xt.dash

+ 23
- 0
dotfiles/config/bashum/main.bashrc 查看文件

@@ -511,6 +511,29 @@ xop() {
511 511
         *)  return 2 ;;
512 512
     esac
513 513
 }
514
+
515
+xt() {
516
+    #
517
+    # Type out selection clipboard content using xdotool
518
+    #
519
+    local stime=${1:-3}
520
+    local body
521
+    snore "$stime"
522
+    body=$(xo)
523
+    xdotool type "$body"
524
+}
525
+
526
+xtt() {
527
+    #
528
+    # Type out C-C clipboard content using xdotool
529
+    #
530
+    local stime=${1:-3}
531
+    local body
532
+    snore "$stime"
533
+    body=$(xoo)
534
+    xdotool type "$body"
535
+}
536
+
514 537
 xdl() {
515 538
     #
516 539
     # Download URL from primary clipboard to path $1

+ 49
- 0
dotfiles/config/i3/macros/xt.dash 查看文件

@@ -0,0 +1,49 @@
1
+#!/bin/bash
2
+
3
+
4
+fixnl () {
5
+    local arg=$1;
6
+    local cache;
7
+    local nlcount;
8
+    local lastchr;
9
+    local single=keep;
10
+    case $arg in 
11
+        -c | --chop-single)
12
+            single=chop
13
+        ;;
14
+    esac;
15
+    cache="$(mktemp -t fixnl.XXXXXXXX)";
16
+    cat > "$cache";
17
+    nlcount=$(<"$cache" wc -l);
18
+    lastchr=$(<"$cache" tail -c1 | hexdump -e '"%02x"');
19
+    case $nlcount:$lastchr:$single in 
20
+        0:??:*)
21
+            cat "$cache"
22
+        ;;
23
+        1:0a:chop)
24
+            head -c -1 "$cache"
25
+        ;;
26
+        1:0a:keep)
27
+            cat "$cache"
28
+        ;;
29
+        *:0a:*)
30
+            cat "$cache"
31
+        ;;
32
+        *:??:*)
33
+            cat "$cache";
34
+            echo
35
+        ;;
36
+    esac;
37
+    rm "$cache"
38
+}
39
+
40
+main () { 
41
+    local body;
42
+    body="$(xclip -o)"
43
+    declare -p body >~/body.declare
44
+    echo -n "$body" | hexdump -C >~/body.hexdump
45
+    sleep 0.5s
46
+    xdotool type "$body"
47
+}
48
+
49
+main "$@"