Pārlūkot izejas kodu

Add utility function to replicate STDIN horizontally

Alois Mahdal 8 mēnešus atpakaļ
vecāks
revīzija
fff4b3a300
1 mainītis faili ar 23 papildinājumiem un 0 dzēšanām
  1. 23
    0
      dotfiles/config/bashum/main.bashrc

+ 23
- 0
dotfiles/config/bashum/main.bashrc Parādīt failu

@@ -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