aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-03-03 01:05:13 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-03-03 01:05:13 +0530
commit3dc1760630a821a39dac0d66a3ed0fa74d099d24 (patch)
tree8fd8b3ecba6866bdeb8dd8e7c90906c8ef340837
parent602ec0e41b684d9ccb4020031b2fd8899edc926d (diff)
downloadnnn-3dc1760630a821a39dac0d66a3ed0fa74d099d24.tar.gz
refactor quitcd
-rw-r--r--src/nnn.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 5020e19..5cebd77 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -1217,6 +1217,25 @@ static void archive_selection(const char *archive, const char *curpath)
spawn("sh", "-c", g_buf, curpath, F_NORMAL | F_SIGINT);
}
+static bool write_lastdir(const char *curpath)
+{
+ char *tmp = getenv(env_cfg[NNN_TMPFILE]);
+
+ if (!tmp) {
+ printmsg("set NNN_TMPFILE");
+ return FALSE;
+ }
+
+ FILE *fp = fopen(tmp, "w");
+
+ if (fp) {
+ fprintf(fp, "cd \"%s\"", curpath);
+ fclose(fp);
+ }
+
+ return TRUE;
+}
+
/*
* Returns:
* FALSE - a message is shown
@@ -3917,23 +3936,8 @@ nochange:
/* Picker mode: reset buffer or clear file */
if (copybufpos)
cfg.pickraw ? copybufpos = 0 : writecp(NULL, 0);
-
- dentfree(dents);
- return;
- }
-
- tmp = getenv(env_cfg[NNN_TMPFILE]);
- if (!tmp) {
- printmsg("set NNN_TMPFILE");
+ } else if (!write_lastdir(path))
goto nochange;
- }
-
- FILE *fp = fopen(tmp, "w");
-
- if (fp) {
- fprintf(fp, "cd \"%s\"", path);
- fclose(fp);
- }
} // fallthrough
case SEL_QUITCTX:
if (sel == SEL_QUITCTX) {