]> Sergey Matveev's repositories - nnn.git/commitdiff
Use double quotes to handle file names with spaces
authorArun Prakash Jana <engineerarun@gmail.com>
Mon, 3 Apr 2017 18:03:31 +0000 (23:33 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Mon, 3 Apr 2017 18:03:31 +0000 (23:33 +0530)
Remove dependency on cut.

nnn.c

diff --git a/nnn.c b/nnn.c
index bc825a29776cc6394f7db4798612073a1f26d7d7..b80b017aed7a8b77442ad4e3750014fbb19d6dc7 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -779,7 +779,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
 
        if (S_ISREG(sb->st_mode)) {
                /* Show file(1) output */
-               sprintf(buf, "file -b %s 2>&1", fpath);
+               sprintf(buf, "file -b \"%s\" 2>&1", fpath);
                p = get_output(buf, PATH_MAX + 48);
                if (p) {
                        printw("\n\n ");
@@ -796,16 +796,30 @@ show_stats(char* fpath, char* fname, struct stat *sb)
                }
 
                /* Show md5 */
-               sprintf(buf, "openssl md5 %s 2>&1 | cut -d' ' -f2", fpath);
+               sprintf(buf, "openssl md5 \"%s\" 2>&1", fpath);
                p = get_output(buf, PATH_MAX + 48);
-               if (p)
+               if (p) {
+                       p = xmemrchr(buf, ' ', strlen(buf));
+                       if (!p)
+                               p = buf;
+                       else
+                               p++;
+
                        printw("\n     md5: %s", p);
+               }
 
                /* Show sha256 */
-               sprintf(buf, "openssl sha256 %s 2>&1| cut -d' ' -f2", fpath);
+               sprintf(buf, "openssl sha256 \"%s\" 2>&1", fpath);
                p = get_output(buf, PATH_MAX + 48);
-               if (p)
+               if (p) {
+                       p = xmemrchr(buf, ' ', strlen(buf));
+                       if (!p)
+                               p = buf;
+                       else
+                               p++;
+
                        printw("  sha256: %s", p);
+               }
        }
 
        /* Show exit keys */