瀏覽代碼

Add utility function to replicate STDIN horizontally

Alois Mahdal 1 月之前
父節點
當前提交
fff4b3a300
共有 1 個文件被更改,包括 23 次插入0 次删除
  1. 23
    0
      dotfiles/config/bashum/main.bashrc

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

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