]> Sergey Matveev's repositories - nnn.git/commitdiff
Optional fortune quotes in help/config page
authorArun Prakash Jana <engineerarun@gmail.com>
Sat, 12 Oct 2019 17:32:44 +0000 (23:02 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Sat, 12 Oct 2019 17:34:34 +0000 (23:04 +0530)
README.md
src/nnn.c

index e4e970c2c3c06cd8ce4f1e7be7c5658da013c390..4dc47363068d821efd85665215a409d2a03ff51c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -95,6 +95,7 @@ A curses library with wide char support (e.g. ncursesw), libreadline (`make O_NO
 | trash-cli | optional | trash files (default action: delete) |
 | vlock (Linux), bashlock (macOS), lock(1) (BSD) | optional | terminal locker (fallback: [cmatrix](https://github.com/abishekvashok/cmatrix)) |
 | advcpmv (Linux) ([integration](https://github.com/jarun/nnn/wiki/Advanced-use-cases#show-cp-mv-progress)) | optional | copy, move progress |
+| fortune | optional | random quotes in help screen |
 | `$VISUAL` (else `$EDITOR`), `$PAGER`, `$SHELL` | optional | fallback vi, less, sh |
 
 #### From a package manager
index 7f2cd5d452229a4bf715e71ebdff6962a7aa3b8c..d154819059068dbe419625a1edb81bb1747940a8 100644 (file)
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -2636,6 +2636,17 @@ static inline bool getutil(char *util)
        return spawn("which", util, NULL, NULL, F_NORMAL | F_NOTRACE) == 0;
 }
 
+static void pipetofd(char *cmd, int fd)
+{
+       FILE *fp = popen(cmd, "r");
+
+       if (fp) {
+               while (fgets(g_buf, CMD_LEN_MAX - 1, fp))
+                       dprintf(fd, "%s", g_buf);
+               pclose(fp);
+       }
+}
+
 /*
  * Follows the stat(1) output closely
  */
@@ -2644,7 +2655,6 @@ static bool show_stats(const char *fpath, const char *fname, const struct stat *
        int fd;
        char *p, *begin = g_buf;
        size_t r;
-       FILE *fp;
 
        fd = create_tmp_file();
        if (fd == -1)
@@ -2656,12 +2666,7 @@ static bool show_stats(const char *fpath, const char *fname, const struct stat *
        g_buf[r - 1] = '\0';
        DPRINTF_S(g_buf);
 
-       fp = popen(g_buf, "r");
-       if (fp) {
-               while (fgets(g_buf, CMD_LEN_MAX - 1, fp))
-                       dprintf(fd, "%s", g_buf);
-               pclose(fp);
-       }
+       pipetofd(g_buf, fd);
 
        if (S_ISREG(sb->st_mode)) {
                /* Show file(1) output */
@@ -2996,6 +3001,9 @@ static void show_help(const char *path)
        if (fd == -1)
                return;
 
+       if (getutil("fortune"))
+               pipetofd("fortune -s", fd);
+
        start = end = helpstr;
        while (*end) {
                if (*end == '\n') {
@@ -4385,11 +4393,11 @@ nochange:
                                break;
                        case SEL_NEW:
                                r = get_input("create 'f'(ile) / 'd'(ir) / 's'(ym) / 'h'(ard)?");
-                               if (r == 'f' || r == 'd') {
+                               if (r == 'f' || r == 'd')
                                        tmp = xreadline(NULL, "name: ");
-                               } else if (r == 's' || r == 'h') {
+                               else if (r == 's' || r == 'h')
                                        tmp = xreadline(NULL, "link suffix [@ for none]: ");
-                               else
+                               else
                                        tmp = NULL;
                                break;
                        default: /* SEL_RENAME */
@@ -4494,9 +4502,9 @@ nochange:
                                if (r == 'f') {
                                        r = openat(fd, tmp, O_CREAT, 0666);
                                        close(r);
-                               } else if (r == 'd') {
+                               } else if (r == 'd')
                                        r = mkdirat(fd, tmp, 0777);
-                               else if (r == 's' || r == 'h') {
+                               else if (r == 's' || r == 'h') {
                                        if (tmp[0] == '@' && tmp[1] == '\0')
                                                tmp[0] = '\0';
                                        r = xlink(tmp, path, newpath, &presel, r);