aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-10-12 23:02:44 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-10-12 23:04:34 +0530
commite371182a5bf5b612ba3dca1abcbc099b341207d7 (patch)
tree9dc55dec8a21df01d2c1d66204ad01e196b02e75
parentec9331de176fe51cdbaf27047c0a14040ec88ae3 (diff)
downloadnnn-e371182a5bf5b612ba3dca1abcbc099b341207d7.tar.gz
Optional fortune quotes in help/config page
-rw-r--r--README.md1
-rw-r--r--src/nnn.c32
2 files changed, 21 insertions, 12 deletions
diff --git a/README.md b/README.md
index e4e970c..4dc4736 100644
--- 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
diff --git a/src/nnn.c b/src/nnn.c
index 7f2cd5d..d154819 100644
--- 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);