Browse Source

Add 'nlfor()' for most common tr syntax ("something to newline')

Alois Mahdal 8 years ago
parent
commit
4b86814460
1 changed files with 20 additions and 0 deletions
  1. 20
    0
      dotfiles/bash/main.bashrc

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

@@ -194,6 +194,26 @@ fixnl() {
194 194
     rm "$cache"
195 195
 }
196 196
 
197
+nlfor() {
198
+    #
199
+    # Replace $1 with newlines and fix final newline
200
+    #
201
+    # Shorthand for commonly used tr syntax.  Example:
202
+    #
203
+    #     $ echo "$PATH" | nlat :
204
+    #     /foo
205
+    #     /bar
206
+    #     $
207
+    #
208
+    # is almost like `tr -n :` except that it is a bit easier
209
+    # to type and fixes the annoying problem with missing
210
+    # newline at the end of the replaced string.
211
+    #
212
+    local char=$1
213
+    tr "$char" '\n' \
214
+      | fixnl
215
+}
216
+
197 217
 xop() {
198 218
     #
199 219
     # Common clipboard operations with fixnl() on top