Browse Source

Add stdin repeaters

lrep() and prep() repeat every line, or whole stream, on stdin
$1 times.
Alois Mahdal 5 years ago
parent
commit
997d7f356f
1 changed files with 33 additions and 0 deletions
  1. 33
    0
      dotfiles/bash/main.bashrc

+ 33
- 0
dotfiles/bash/main.bashrc View File

@@ -44,6 +44,39 @@ pp() {
44 44
     read -r junk -p "Press Enter to continue"
45 45
 }
46 46
 
47
+lrep() {
48
+    #
49
+    # Print each line on STDIN $1 times
50
+    #
51
+    local rep=${1:-1}; shift
52
+    local line
53
+    local n
54
+    while read -r line; do
55
+        n=$rep
56
+        while test "$n" -gt 0;
57
+        do
58
+            echo "$line"
59
+            ((n--))
60
+        done
61
+    done
62
+}
63
+
64
+prep() {
65
+    #
66
+    # Print STDIN $1 times
67
+    #
68
+    local rep=${1:-1}; shift
69
+    local data
70
+    data=$(cat)
71
+    n=$rep
72
+    while test "$n" -gt 0;
73
+    do
74
+        echo "$data"
75
+        echo
76
+        ((n--))
77
+    done
78
+}
79
+
47 80
 dt() {
48 81
     #
49 82
     # Open $1 new terminals