nnn

mirror of https://github.com/jarun/nnn
Log | Files | Refs | README | LICENSE

commit dd00a37b827e90517df25a4b6baef0184d605b18
parent feea0a18b2833760037b56d868248d9b694b4181
Author: Arun Prakash Jana <engineerarun@gmail.com>
Date:   Sat, 18 Apr 2026 21:00:57 +0530

Revert "Change directory with cd at the prompt"

This reverts commit 7e66a5ec08afa16e8a609b2e02a6087a44cf78f6.

Diffstat:
Msrc/nnn.c | 65++++-------------------------------------------------------------
1 file changed, 4 insertions(+), 61 deletions(-)

diff --git a/src/nnn.c b/src/nnn.c @@ -6653,7 +6653,7 @@ static bool launch_app(char *newpath) } /* Returns TRUE if at least one command was run */ -static bool prompt_run(char *path, char *lastdir) +static bool prompt_run(void) { bool ret = FALSE; char *cmdline, *next; @@ -6719,63 +6719,6 @@ static bool prompt_run(char *path, char *lastdir) else if (cnt_J) snprintf(cmd, CMD_LEN_MAX + 32, xargs_J, cmdline, selpath); - /* Pre-parse cd command before spawn overwrites cmdline (g_buf) */ - bool is_cd = (!cnt_j && !cnt_J - && cmdline[0] == 'c' && cmdline[1] == 'd' - && (cmdline[2] == '\0' || cmdline[2] == ' ')); - bool is_cd_dash = false; - - cmd[0] = '\0'; - if (is_cd) { - const char *dir = NULL; - - if (cmdline[2] == '\0' || cmdline[3] == '\0' - || (cmdline[3] == '~' && (cmdline[4] == '\0' || cmdline[4] == ' '))) - dir = home; - else if (cmdline[3] == '-' && (cmdline[4] == '\0' || cmdline[4] == ' ')) { - dir = lastdir; - is_cd_dash = true; - } else if (cmdline[3] == '~' && cmdline[4] == '/') { - snprintf(cmd, PATH_MAX, "%s%s", home, cmdline + 4); - dir = cmd; - } else - dir = cmdline + 3; - - if (dir && *dir) { - if (is_cd_dash) { - xstrsncpy(cmd, dir, PATH_MAX); - } else { - /* Strip single quotes from shell-escaped path */ - const char *s = dir; - size_t d = 0; - - while (*s && d < PATH_MAX - 1) { - if (*s == '\'') { - ++s; - continue; - } - if (*s == '\\' && s[1] == '\'') { - cmd[d++] = '\''; - s += 2; - continue; - } - cmd[d++] = *s++; - } - cmd[d] = '\0'; - } - } - } - - /* Sync nnn directory with cd */ - if (is_cd && cmd[0]) { - if (realpath(cmd, g_buf) && xdiraccess(g_buf)) { - xstrsncpy(lastdir, path, PATH_MAX); - xstrsncpy(path, g_buf, PATH_MAX); - clearfilter(); - break; - } - } - cmd_ret = spawn(shell, "-c", (cnt_j || cnt_J) ? cmd : cmdline, NULL, F_CLI | F_CONFIRM); if ((cnt_j || cnt_J) && cmd_ret == 0) clearselection(); @@ -6784,7 +6727,7 @@ static bool prompt_run(char *path, char *lastdir) return ret; } -static bool handle_cmd(enum action sel, char *path, char *newpath, char *lastdir) +static bool handle_cmd(enum action sel, char *path, char *newpath) { endselection(FALSE); @@ -6794,7 +6737,7 @@ static bool handle_cmd(enum action sel, char *path, char *newpath, char *lastdir setexports(path); if (sel == SEL_PROMPT) - return prompt_run(path, lastdir); + return prompt_run(); /* Set nnn nesting level */ char *tmp = getenv(env_cfg[NNNLVL]); @@ -9720,7 +9663,7 @@ nochange: case SEL_SHELL: // fallthrough case SEL_LAUNCH: // fallthrough case SEL_PROMPT: - r = handle_cmd(sel, path, newpath, lastdir); + r = handle_cmd(sel, path, newpath); /* Continue in type-to-nav mode, if enabled */ if (cfg.filtermode)