]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix some cat abuses in code, plugins
authorArun Prakash Jana <engineerarun@gmail.com>
Wed, 20 Nov 2019 19:01:39 +0000 (00:31 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Wed, 20 Nov 2019 19:01:39 +0000 (00:31 +0530)
misc/clipboard-copier/copier
plugins/fzhist
plugins/ndiff
plugins/picker
plugins/readit
src/nnn.c

index 92f7dcede7a9f793fafaf56b13dd856c4695feb3..6ac3ba6b2fe28ef8055b44ed0ece0f051f5877ed 100755 (executable)
@@ -8,16 +8,16 @@
 SELECTION=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection
 
 # Linux
-cat "$SELECTION" | xargs -0 | xsel -bi
+xargs -0 < "$SELECTION" | xsel -bi
 
 # macOS
-# cat "$SELECTION" | xargs -0 | pbcopy
+# xargs -0 < "$SELECTION" | pbcopy
 
 # Termux
-# cat "$SELECTION" | xargs -0 | termux-clipboard-set
+# xargs -0 < "$SELECTION" | termux-clipboard-set
 
 # Cygwin
-# cat "$SELECTION" | xargs -0 | clip
+# xargs -0 < "$SELECTION" | clip
 
 # Wayland
-# cat "$SELECTION" | xargs -0 | wl-copy
+# xargs -0 < "$SELECTION" | wl-copy
index 52f13bfd0fbdbf20d20c5dc0e7cc47f346d9c573..ca1db630b5a8bef9a7402287b34880e618e83d7e 100755 (executable)
@@ -10,10 +10,10 @@ shellname="$(basename "$SHELL")"
 
 if [ "$shellname" = "bash" ]; then
     hist_file="$HOME/.bash_history"
-    entry="$(cat "$hist_file" | fzy)"
+    entry="$(fzy < "$hist_file")"
 elif [ "$shellname" = "fish" ]; then
     hist_file="$HOME/.config/fish/fish_history"
-    entry="$(cat "$hist_file" | grep "\- cmd: " | cut -c 8- | fzy)"
+    entry="$(grep "\- cmd: " "$hist_file" | cut -c 8- | fzy)"
 fi
 
 if ! [ -z "$entry" ]; then
@@ -21,10 +21,8 @@ if ! [ -z "$entry" ]; then
     echo "$entry" >> $tmpfile
     $EDITOR $tmpfile
 
-    cmd="$(cat $tmpfile)"
-
-    if ! [ -z "$cmd" ]; then
-        $SHELL -c "$cmd"
+    if [ -s $tmpfile ]; then
+        $SHELL -c "$(cat $tmpfile)"
     fi
 
     rm $tmpfile
index dff24d2511eb062e87cce12d3520b942179e2dd0..f5ca0dc3f2985a5bf607eb1394f07fcaf94b7569 100755 (executable)
@@ -25,9 +25,9 @@ if [ -s $selection ]; then
         else
             # If xargs supports the -o option, use it to get rid of:
             #     Vim: Warning: Input is not from a terminal
-            # cat $selection | xargs -0 -o vimdiff
+            # xargs -0 -o vimdiff < $selection
 
-            cat $selection | xargs -0 vimdiff +0
+            xargs -0 vimdiff +0 < $selection
         fi
     else
         echo "needs at least 2 files or directories selected for comparison"
index a5004359c67f730697692ac4fb473937d4208f82..91101fea1b4375e6bb9feae6703ab9aa73a526fb 100755 (executable)
@@ -21,6 +21,6 @@
 nnn -p /tmp/picked
 
 if [ -f /tmp/picked ]; then
-    cat /tmp/picked | tr '\0' '\n'
+    tr '\0' '\n' < /tmp/picked
     rm /tmp/picked
 fi
index b997235afea5df67d6d854293d33b50e1eb9dfce..e0058dbf3078864caa88fa36485b0bb750b3d29c 100755 (executable)
@@ -13,11 +13,11 @@ if ! [ -z "$1" ]; then
         # Convert using pdftotext
         pdftotext -nopgbrk -layout "$1" - | sed 's/\xe2\x80\x8b//g' > "$tmpf".txt
 
-        pico2wave -w "$tmpf".wav -l en-GB "$(cat "$tmpf".txt | tr '\n' ' ')"
+        pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$tmpf".txt)"
 
         rm "$tmpf".txt
     else
-        pico2wave -w "$tmpf".wav -l en-GB "$(cat "$1" | tr '\n' ' ')"
+        pico2wave -w "$tmpf".wav -l en-GB "$(tr '\n' ' ' < "$1")"
     fi
 
     # to jump around and note the time
index db6108bfae7b109139492d8c77f095f1552714fe..52347ff2d77358bcf662eb2520f40bd16c271b77 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -891,7 +891,7 @@ static bool listselfile(void)
        if (!sb.st_size)
                return FALSE;
 
-       snprintf(g_buf, CMD_LEN_MAX, "cat %s | tr \'\\0\' \'\\n\'", g_selpath);
+       snprintf(g_buf, CMD_LEN_MAX, "tr \'\\0\' \'\\n\' < %s", g_selpath);
        spawn(utils[SH_EXEC], g_buf, NULL, NULL, F_CLI | F_CONFIRM);
 
        return TRUE;
@@ -1346,7 +1346,7 @@ static bool cpmv_rename(int choice, const char *path)
 
        /* selsafe() returned TRUE for this to be called */
        if (!selbufpos) {
-               snprintf(buf, sizeof(buf), "cat %s | tr '\\0' '\\n' > %s", g_selpath, g_tmpfpath);
+               snprintf(buf, sizeof(buf), "tr '\\0' '\\n' < %s > %s", g_selpath, g_tmpfpath);
                spawn(utils[SH_EXEC], buf, NULL, NULL, F_CLI);
 
                count = lines_in_file(fd, buf, sizeof(buf));