Browse Source

Add utility function to replicate STDIN horizontally

Alois Mahdal 8 months ago
parent
commit
fff4b3a300
1 changed files with 23 additions and 0 deletions
  1. 23
    0
      dotfiles/config/bashum/main.bashrc

+ 23
- 0
dotfiles/config/bashum/main.bashrc View File

@@ -128,6 +128,29 @@ pp() {
128 128
     read -r junk -p "Press Enter to continue"
129 129
 }
130 130
 
131
+wrep() {
132
+    #
133
+    # Print each line on STDIN $1 times horizontally
134
+    #
135
+    echo >&2 "use sdup -w instead!"
136
+    local rep=${1:-1}; shift
137
+    local delim=${1:-" "}; shift
138
+    local line
139
+    local n
140
+    while read -r line; do
141
+        local head=true
142
+        n=$rep
143
+        while test "$n" -gt 0;
144
+        do
145
+            $head || echo -n "$delim"
146
+            $head && head=false
147
+            echo -n "$line"
148
+            ((n--))
149
+        done
150
+        echo
151
+    done
152
+}
153
+
131 154
 lrep() {
132 155
     #
133 156
     # Print each line on STDIN $1 times