Browse Source

Use `[:blank:]` or space as default split/join character

Alois Mahdal 6 years ago
parent
commit
b0b2b2362b
1 changed files with 4 additions and 2 deletions
  1. 4
    2
      dotfiles/bash/main.bashrc

+ 4
- 2
dotfiles/bash/main.bashrc View File

@@ -236,7 +236,7 @@ mdvimb() {
236 236
 
237 237
 nlfor() {
238 238
     #
239
-    # Replace $1 with newlines and fix final newline
239
+    # Replace $1 (or blank space) with newlines and fix final newline
240 240
     #
241 241
     # Shorthand for commonly used tr syntax.  Example:
242 242
     #
@@ -250,13 +250,14 @@ nlfor() {
250 250
     # newline at the end of the replaced string.
251 251
     #
252 252
     local char=$1
253
+    test -n "$char" || char='[:blank:]'
253 254
     tr "$char" '\n' \
254 255
       | fixnl
255 256
 }
256 257
 
257 258
 nljoin() {
258 259
     #
259
-    # Join lines with $1
260
+    # Join lines with $1 (or space)
260 261
     #
261 262
     # Shorthand for commonly used tr syntax.  Example:
262 263
     #
@@ -267,6 +268,7 @@ nljoin() {
267 268
     # newline/colon at the end of final string.
268 269
     #
269 270
     local char=$1
271
+    test -n "$char" || char=' '
270 272
     tr '\n' "$char" \
271 273
       | sed "s/$char*$//" \
272 274
       | fixnl -c