mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Move cd on quit file
The new location is ~/.config/nnn/.lastd
This commit is contained in:
parent
cd458b9ab4
commit
fa4f082ac0
|
@ -373,7 +373,6 @@ The following indicators are used in the detail view:
|
||||||
| `NNN_IDLE_TIMEOUT=300` | idle seconds before locking terminal [default: disabled] |
|
| `NNN_IDLE_TIMEOUT=300` | idle seconds before locking terminal [default: disabled] |
|
||||||
| `NNN_COPIER='/absolute/path/to/copier'` | system clipboard copier script [default: none] |
|
| `NNN_COPIER='/absolute/path/to/copier'` | system clipboard copier script [default: none] |
|
||||||
| `NNN_NOTE=/home/user/Dropbox/notes` | path to note file [default: none] |
|
| `NNN_NOTE=/home/user/Dropbox/notes` | path to note file [default: none] |
|
||||||
| `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit |
|
|
||||||
| `NNN_USE_EDITOR=1` | open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) |
|
| `NNN_USE_EDITOR=1` | open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) |
|
||||||
| `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type_ mode |
|
| `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type_ mode |
|
||||||
| `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd> ↵</kbd>, not <kbd>→</kbd> or <kbd>l</kbd> |
|
| `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd> ↵</kbd>, not <kbd>→</kbd> or <kbd>l</kbd> |
|
||||||
|
|
5
nnn.1
5
nnn.1
|
@ -174,11 +174,6 @@ when dealing with the !, e and p commands respectively. A single combination to
|
||||||
export NNN_NOTE='/home/user/.mynotes'
|
export NNN_NOTE='/home/user/.mynotes'
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_TMPFILE:\fR when cd on quit is pressed, the absolute path of the current open directory is written to this file. A wrapper script can read this file and cd into it once the program quits.
|
|
||||||
.Bd -literal
|
|
||||||
export NNN_TMPFILE=/tmp/nnn
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
\fBNNN_USE_EDITOR:\fR use EDITOR (VISUAL takes preference, preferably CLI, fallback vi) to handle text
|
\fBNNN_USE_EDITOR:\fR use EDITOR (VISUAL takes preference, preferably CLI, fallback vi) to handle text
|
||||||
files.
|
files.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
export NNN_TMPFILE="/tmp/nnn"
|
|
||||||
|
|
||||||
n()
|
n()
|
||||||
{
|
{
|
||||||
nnn "$@"
|
nnn "$@"
|
||||||
|
|
||||||
|
NNN_TMPFILE=~/.config/nnn/.lastd
|
||||||
|
|
||||||
if [ -f $NNN_TMPFILE ]; then
|
if [ -f $NNN_TMPFILE ]; then
|
||||||
. $NNN_TMPFILE
|
. $NNN_TMPFILE
|
||||||
rm -f $NNN_TMPFILE > /dev/null
|
rm -f $NNN_TMPFILE > /dev/null
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
setenv NNN_TMPFILE /tmp/nnn
|
set NNN_TMPFILE=~/.config/nnn/.lastd
|
||||||
|
|
||||||
alias n 'nnn; source "$NNN_TMPFILE"; rm "$NNN_TMPFILE"'
|
alias n 'nnn; source "$NNN_TMPFILE"; rm "$NNN_TMPFILE"'
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
# e.g. ~/.config/fish/functions/n.fish
|
# e.g. ~/.config/fish/functions/n.fish
|
||||||
# or, add the lines to the 'config.fish' file.
|
# or, add the lines to the 'config.fish' file.
|
||||||
|
|
||||||
export NNN_TMPFILE="/tmp/nnn"
|
|
||||||
|
|
||||||
function n --description 'support nnn quit and change directory'
|
function n --description 'support nnn quit and change directory'
|
||||||
nnn $argv
|
nnn $argv
|
||||||
|
|
||||||
|
set NNN_TMPFILE ~/.config/nnn/.lastd
|
||||||
|
|
||||||
if test -e $NNN_TMPFILE
|
if test -e $NNN_TMPFILE
|
||||||
source $NNN_TMPFILE
|
source $NNN_TMPFILE
|
||||||
rm $NNN_TMPFILE
|
rm $NNN_TMPFILE
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
export NNN_TMPFILE="/tmp/nnn"
|
|
||||||
|
|
||||||
n()
|
n()
|
||||||
{
|
{
|
||||||
nnn "$@"
|
nnn "$@"
|
||||||
|
|
||||||
|
NNN_TMPFILE=~/.config/nnn/.lastd
|
||||||
|
|
||||||
if [ -f $NNN_TMPFILE ]; then
|
if [ -f $NNN_TMPFILE ]; then
|
||||||
. $NNN_TMPFILE
|
. $NNN_TMPFILE
|
||||||
rm $NNN_TMPFILE
|
rm $NNN_TMPFILE
|
||||||
|
|
36
src/nnn.c
36
src/nnn.c
|
@ -391,14 +391,13 @@ static const char * const messages[] = {
|
||||||
#define NNN_IDLE_TIMEOUT 3
|
#define NNN_IDLE_TIMEOUT 3
|
||||||
#define NNN_COPIER 4
|
#define NNN_COPIER 4
|
||||||
#define NNN_NOTE 5
|
#define NNN_NOTE 5
|
||||||
#define NNN_TMPFILE 6
|
#define NNNLVL 6 /* strings end here */
|
||||||
#define NNNLVL 7 /* strings end here */
|
#define NNN_USE_EDITOR 7 /* flags begin here */
|
||||||
#define NNN_USE_EDITOR 8 /* flags begin here */
|
#define NNN_NO_AUTOSELECT 8
|
||||||
#define NNN_NO_AUTOSELECT 9
|
#define NNN_RESTRICT_NAV_OPEN 9
|
||||||
#define NNN_RESTRICT_NAV_OPEN 10
|
#define NNN_TRASH 10
|
||||||
#define NNN_TRASH 11
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define NNN_OPS_PROG 12
|
#define NNN_OPS_PROG 11
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char * const env_cfg[] = {
|
static const char * const env_cfg[] = {
|
||||||
|
@ -408,7 +407,6 @@ static const char * const env_cfg[] = {
|
||||||
"NNN_IDLE_TIMEOUT",
|
"NNN_IDLE_TIMEOUT",
|
||||||
"NNN_COPIER",
|
"NNN_COPIER",
|
||||||
"NNN_NOTE",
|
"NNN_NOTE",
|
||||||
"NNN_TMPFILE",
|
|
||||||
"NNNLVL",
|
"NNNLVL",
|
||||||
"NNN_USE_EDITOR",
|
"NNN_USE_EDITOR",
|
||||||
"NNN_NO_AUTOSELECT",
|
"NNN_NO_AUTOSELECT",
|
||||||
|
@ -1221,21 +1219,23 @@ static void archive_selection(const char *cmd, const char *archive, const char *
|
||||||
|
|
||||||
static bool write_lastdir(const char *curpath)
|
static bool write_lastdir(const char *curpath)
|
||||||
{
|
{
|
||||||
char *tmp = getenv(env_cfg[NNN_TMPFILE]);
|
bool ret = TRUE;
|
||||||
|
size_t len = strlen(cfgdir);
|
||||||
|
|
||||||
if (!tmp) {
|
xstrlcpy(cfgdir + len, "/.lastd", 8);
|
||||||
printmsg("set NNN_TMPFILE");
|
DPRINTF_S(cfgdir);
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *fp = fopen(tmp, "w");
|
FILE *fp = fopen(cfgdir, "w");
|
||||||
|
|
||||||
if (fp) {
|
if (fp) {
|
||||||
fprintf(fp, "cd \"%s\"", curpath);
|
if (fprintf(fp, "cd \"%s\"", curpath) < 0)
|
||||||
fclose(fp);
|
ret = FALSE;
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
fclose(fp);
|
||||||
|
} else
|
||||||
|
ret = FALSE;
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int digit_compare(const char *a, const char *b)
|
static int digit_compare(const char *a, const char *b)
|
||||||
|
|
Loading…
Reference in a new issue