mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Fix #350: cd on quit if NNN_TMPFILE is set
This commit is contained in:
parent
c99a47d688
commit
d1d491c102
|
@ -1,5 +1,7 @@
|
|||
n()
|
||||
{
|
||||
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
|
||||
# To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
|
||||
export NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd
|
||||
|
||||
nnn "$@"
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
# NOTE: set NNN_TMPFILE correctly if you use 'XDG_CONFIG_HOME'
|
||||
|
||||
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
|
||||
# To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
|
||||
set NNN_TMPFILE=~/.config/nnn/.lastd
|
||||
|
||||
alias n 'nnn; source "$NNN_TMPFILE"; rm "$NNN_TMPFILE"'
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# or, add the lines to the 'config.fish' file.
|
||||
|
||||
function n --description 'support nnn quit and change directory'
|
||||
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
|
||||
# To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
|
||||
if test -n "$XDG_CONFIG_HOME"
|
||||
set -x NNN_TMPFILE "$XDG_CONFIG_HOME/nnn/.lastd"
|
||||
else
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
n()
|
||||
{
|
||||
# The default behaviour is to cd on quit (nnn checks if NNN_TMPFILE is set)
|
||||
# To cd on quit only on ^G, export NNN_TMPFILE after the call to nnn
|
||||
export NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd
|
||||
|
||||
nnn "$@"
|
||||
|
|
5
nnn.1
5
nnn.1
|
@ -95,11 +95,6 @@ supports the following options:
|
|||
uses \fIxdg-open\fR (on Linux) and \fIopen(1)\fR (on macOS) as the desktop opener.
|
||||
.Pp
|
||||
There is no configuration file. Associated files are stored in \fB${XDG_CONFIG_HOME:-$HOME/.config}/nnn/\fR. Settings work on environment variables. See ENVIRONMENT section below.
|
||||
.Pp
|
||||
Configuring
|
||||
.Nm
|
||||
to change to the last visited directory on quit requires shell integration in a
|
||||
few easy steps. Look up NNN_TMPFILE in the ENVIRONMENT section below.
|
||||
.Sh CONTEXTS
|
||||
Contexts serve the purpose of exploring multiple directories simultaneously. 4 contexts
|
||||
are available. The status of the contexts are shown in the top left corner:
|
||||
|
|
32
src/nnn.c
32
src/nnn.c
|
@ -4603,21 +4603,9 @@ nochange:
|
|||
}
|
||||
|
||||
if (!(r == CTX_MAX || r == '\r'))
|
||||
break;
|
||||
|
||||
if (sel == SEL_QUITCD) {
|
||||
/* In vim picker mode, clear selection and exit */
|
||||
if (cfg.picker) {
|
||||
/* Picker mode: reset buffer or clear file */
|
||||
if (selbufpos)
|
||||
cfg.pickraw ? selbufpos = 0 : writesel(NULL, 0);
|
||||
} else if (!write_lastdir(path)) {
|
||||
presel = MSGWAIT;
|
||||
goto nochange;
|
||||
}
|
||||
}
|
||||
return;
|
||||
break; // fallthrough
|
||||
case SEL_QUITCTX:
|
||||
if (sel == SEL_QUITCTX) {
|
||||
fd = cfg.curctx; /* fd used as tmp var */
|
||||
for (r = (fd + 1) & ~CTX_MAX;
|
||||
(r != fd) && !g_ctx[r].c_cfg.ctxactive;
|
||||
|
@ -4637,7 +4625,8 @@ nochange:
|
|||
/* Switch light/detail mode */
|
||||
if (cfg.showdetail != g_ctx[r].c_cfg.showdetail)
|
||||
/* Set the reverse */
|
||||
printptr = cfg.showdetail ? &printent : &printent_long;
|
||||
printptr = cfg.showdetail ?
|
||||
&printent : &printent_long;
|
||||
|
||||
cfg = g_ctx[r].c_cfg;
|
||||
|
||||
|
@ -4647,6 +4636,19 @@ nochange:
|
|||
setdirwatch();
|
||||
goto begin;
|
||||
}
|
||||
}
|
||||
|
||||
if (sel == SEL_QUITCD || getenv("NNN_TMPFILE")) {
|
||||
/* In vim picker mode, clear selection and exit */
|
||||
if (cfg.picker) {
|
||||
/* Picker mode: reset buffer or clear file */
|
||||
if (selbufpos)
|
||||
cfg.pickraw ? selbufpos = 0 : writesel(NULL, 0);
|
||||
} else if (!write_lastdir(path)) {
|
||||
presel = MSGWAIT;
|
||||
goto nochange;
|
||||
}
|
||||
}
|
||||
return;
|
||||
default:
|
||||
if (xlines != LINES || xcols != COLS) {
|
||||
|
|
Loading…
Reference in a new issue