aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-11-13 12:40:57 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-11-13 12:40:57 +0530
commit74cd15c232ffbe5f77be547abef4ab6ff6b33fcf (patch)
tree4ea4adbf8236e542dd89030a45ba0535bb74041f /src
parentb09adb4654ea68e27b91a96b8e2bfd96a1378971 (diff)
downloadnnn-74cd15c232ffbe5f77be547abef4ab6ff6b33fcf.tar.gz
Q - error & quit if no selection, else pick & quit
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c16
-rw-r--r--src/nnn.h4
2 files changed, 15 insertions, 5 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 78c9546..466acaf 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -4602,6 +4602,7 @@ static void show_help(const char *path)
"aEsc Send to FIFO%-11c^L Redraw\n"
"c? Help, conf%-13c^G QuitCD\n"
"cq Quit context%-6c^Q 2Esc Quit\n"
+ "cQ Pick sel/err & quit\n"
"1FILTER & PROMPT\n"
"c/ Filter%-12cAlt+Esc Clear filter & redraw\n"
"aEsc Exit prompt%-12c^L Clear prompt/last filter\n"
@@ -7036,7 +7037,7 @@ nochange:
case SEL_QUITCTX: // fallthrough
case SEL_QUITCD: // fallthrough
case SEL_QUIT:
- case SEL_QUITFAIL:
+ case SEL_QUITERR:
if (sel == SEL_QUITCTX) {
int ctx = cfg.curctx;
for (r = (ctx + 1) & ~CTX_MAX;
@@ -7086,7 +7087,16 @@ nochange:
if (g_state.picker)
selbufpos = 0;
}
- return sel == SEL_QUITFAIL ? EXIT_FAILURE : EXIT_SUCCESS;
+
+ if (sel != SEL_QUITERR)
+ return EXIT_SUCCESS;
+
+ if (selbufpos && !g_state.picker) {
+ g_state.pickraw = 1;
+ return EXIT_SUCCESS;
+ }
+
+ return EXIT_FAILURE;
default:
if (xlines != LINES || xcols != COLS)
continue;
@@ -7926,7 +7936,7 @@ int main(int argc, char *argv[])
if (g_state.pickraw || g_state.picker) {
if (selbufpos) {
- fd = g_state.pickraw ? 1 : open(selpath, O_WRONLY | O_CREAT, 0600);
+ fd = g_state.pickraw ? STDOUT_FILENO : open(selpath, O_WRONLY | O_CREAT, 0600);
if ((fd == -1) || (seltofile(fd, NULL) != (size_t)(selbufpos)))
xerror();
diff --git a/src/nnn.h b/src/nnn.h
index 55ceacf..222d1a9 100644
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -111,7 +111,7 @@ enum action {
SEL_QUITCTX,
SEL_QUITCD,
SEL_QUIT,
- SEL_QUITFAIL,
+ SEL_QUITERR,
#ifndef NOMOUSE
SEL_CLICK,
#endif
@@ -270,7 +270,7 @@ static struct key bindings[] = {
/* Quit */
{ CONTROL('Q'), SEL_QUIT },
/* Quit with an error code */
- { 'Q', SEL_QUITFAIL },
+ { 'Q', SEL_QUITERR },
#ifndef NOMOUSE
{ KEY_MOUSE, SEL_CLICK },
#endif