Parcourir la source

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

Alois Mahdal il y a 6 ans
Parent
révision
b0b2b2362b
1 fichiers modifiés avec 4 ajouts et 2 suppressions
  1. 4
    2
      dotfiles/bash/main.bashrc

+ 4
- 2
dotfiles/bash/main.bashrc Voir le fichier

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