Bladeren bron

Add nljoin() for joining lines (reverse of nlfor())

Alois Mahdal 7 jaren geleden
bovenliggende
commit
4c1e2e0d9f
1 gewijzigde bestanden met toevoegingen van 18 en 0 verwijderingen
  1. 18
    0
      dotfiles/bash/main.bashrc

+ 18
- 0
dotfiles/bash/main.bashrc Bestand weergeven

220
       | fixnl
220
       | fixnl
221
 }
221
 }
222
 
222
 
223
+nljoin() {
224
+    #
225
+    # Join lines with $1
226
+    #
227
+    # Shorthand for commonly used tr syntax.  Example:
228
+    #
229
+    #     $ { echo foo; echo bar; } | nljoin :
230
+    #
231
+    # is almost like `tr '\n' :` except that it is a bit easier
232
+    # to type and fixes the annoying problem with extraneous
233
+    # newline/colon at the end of final string.
234
+    #
235
+    local char=$1
236
+    tr '\n' "$char" \
237
+      | sed "s/$char*$//" \
238
+      | fixnl -c
239
+}
240
+
223
 xop() {
241
 xop() {
224
     #
242
     #
225
     # Common clipboard operations with fixnl() on top
243
     # Common clipboard operations with fixnl() on top