Browse Source

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

Alois Mahdal 7 years ago
parent
commit
4c1e2e0d9f
1 changed files with 18 additions and 0 deletions
  1. 18
    0
      dotfiles/bash/main.bashrc

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

@@ -220,6 +220,24 @@ nlfor() {
220 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 241
 xop() {
224 242
     #
225 243
     # Common clipboard operations with fixnl() on top