README.md | 1 - nnn.1 | 5 ----- scripts/quitcd/quitcd.bash | 14 +++++++------- scripts/quitcd/quitcd.csh | 3 +-- scripts/quitcd/quitcd.fish | 14 +++++++------- scripts/quitcd/quitcd.zsh | 14 +++++++------- src/nnn.c | 34 +++++++++++++++++----------------- diff --git a/README.md b/README.md index 9bc354102a416d61391ecc1c5e983d96a69082a0..95f2ff57ec33779399fc6d200aff133ac8494444 100644 --- a/README.md +++ b/README.md @@ -373,7 +373,6 @@ | `NNN_CONTEXT_COLORS='1234'` | specify per context color [default: '4444' (all blue)] | | `NNN_IDLE_TIMEOUT=300` | idle seconds before locking terminal [default: disabled] | | `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_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_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type_ mode | | `NNN_RESTRICT_NAV_OPEN=1` | open files on , not or l | diff --git a/nnn.1 b/nnn.1 index 31cbc9ffdfce5af93e0aa468edc1edd394b87685..9f6285863b9ddeee1e085ffefc54b34303b639fb 100644 --- a/nnn.1 +++ b/nnn.1 @@ -174,11 +174,6 @@ .Bd -literal export NNN_NOTE='/home/user/.mynotes' .Ed .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 files. .Bd -literal diff --git a/scripts/quitcd/quitcd.bash b/scripts/quitcd/quitcd.bash index a4482e458e1250ff9e1400c4a8e770df8c6b2336..85b028ac444053716a970ce562e2d9b38ea9422e 100644 --- a/scripts/quitcd/quitcd.bash +++ b/scripts/quitcd/quitcd.bash @@ -1,11 +1,11 @@ -export NNN_TMPFILE="/tmp/nnn" - n() { - nnn "$@" + nnn "$@" - if [ -f $NNN_TMPFILE ]; then - . $NNN_TMPFILE - rm -f $NNN_TMPFILE > /dev/null - fi + NNN_TMPFILE=~/.config/nnn/.lastd + + if [ -f $NNN_TMPFILE ]; then + . $NNN_TMPFILE + rm -f $NNN_TMPFILE > /dev/null + fi } diff --git a/scripts/quitcd/quitcd.csh b/scripts/quitcd/quitcd.csh index 8feabcfe41c1c691e3b432f8313706f11ca5d8ed..62e989797da7c25e7aa65b03fe081dd543bb0c65 100644 --- a/scripts/quitcd/quitcd.csh +++ b/scripts/quitcd/quitcd.csh @@ -1,3 +1,2 @@ -setenv NNN_TMPFILE /tmp/nnn - +set NNN_TMPFILE=~/.config/nnn/.lastd alias n 'nnn; source "$NNN_TMPFILE"; rm "$NNN_TMPFILE"' diff --git a/scripts/quitcd/quitcd.fish b/scripts/quitcd/quitcd.fish index 748f0ddbacd78ad368add7e906d9e597ed595327..347801440ffb34fcff3cbfca2044d1a79adf7de4 100644 --- a/scripts/quitcd/quitcd.fish +++ b/scripts/quitcd/quitcd.fish @@ -2,13 +2,13 @@ # Rename this file to match the name of the function # e.g. ~/.config/fish/functions/n.fish # or, add the lines to the 'config.fish' file. -export NNN_TMPFILE="/tmp/nnn" - function n --description 'support nnn quit and change directory' - nnn $argv + nnn $argv - if test -e $NNN_TMPFILE - source $NNN_TMPFILE - rm $NNN_TMPFILE - end + set NNN_TMPFILE ~/.config/nnn/.lastd + + if test -e $NNN_TMPFILE + source $NNN_TMPFILE + rm $NNN_TMPFILE + end end diff --git a/scripts/quitcd/quitcd.zsh b/scripts/quitcd/quitcd.zsh index dc83b23cbe6c53cb6e6ad7fd346c0d9684bc8925..79f5a03042fdce68ddb8f6ea5b9a756df7bc44a0 100644 --- a/scripts/quitcd/quitcd.zsh +++ b/scripts/quitcd/quitcd.zsh @@ -1,11 +1,11 @@ -export NNN_TMPFILE="/tmp/nnn" - n() { - nnn "$@" + nnn "$@" - if [ -f $NNN_TMPFILE ]; then - . $NNN_TMPFILE - rm $NNN_TMPFILE - fi + NNN_TMPFILE=~/.config/nnn/.lastd + + if [ -f $NNN_TMPFILE ]; then + . $NNN_TMPFILE + rm $NNN_TMPFILE + fi } diff --git a/src/nnn.c b/src/nnn.c index 3d2d46132b3f3cc1ad64acc49ac0fd7f810250e7..161b7dba9c701e3179aa0acf0c1043c936713bb6 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -391,14 +391,13 @@ #define NNN_CONTEXT_COLORS 2 #define NNN_IDLE_TIMEOUT 3 #define NNN_COPIER 4 #define NNN_NOTE 5 -#define NNN_TMPFILE 6 -#define NNNLVL 7 /* strings end here */ -#define NNN_USE_EDITOR 8 /* flags begin here */ -#define NNN_NO_AUTOSELECT 9 -#define NNN_RESTRICT_NAV_OPEN 10 -#define NNN_TRASH 11 +#define NNNLVL 6 /* strings end here */ +#define NNN_USE_EDITOR 7 /* flags begin here */ +#define NNN_NO_AUTOSELECT 8 +#define NNN_RESTRICT_NAV_OPEN 9 +#define NNN_TRASH 10 #ifdef __linux__ -#define NNN_OPS_PROG 12 +#define NNN_OPS_PROG 11 #endif static const char * const env_cfg[] = { @@ -408,7 +407,6 @@ "NNN_CONTEXT_COLORS", "NNN_IDLE_TIMEOUT", "NNN_COPIER", "NNN_NOTE", - "NNN_TMPFILE", "NNNLVL", "NNN_USE_EDITOR", "NNN_NO_AUTOSELECT", @@ -1221,21 +1219,23 @@ } static bool write_lastdir(const char *curpath) { - char *tmp = getenv(env_cfg[NNN_TMPFILE]); + bool ret = TRUE; + size_t len = strlen(cfgdir); - if (!tmp) { - printmsg("set NNN_TMPFILE"); - return FALSE; - } + xstrlcpy(cfgdir + len, "/.lastd", 8); + DPRINTF_S(cfgdir); - FILE *fp = fopen(tmp, "w"); + FILE *fp = fopen(cfgdir, "w"); if (fp) { - fprintf(fp, "cd \"%s\"", curpath); + if (fprintf(fp, "cd \"%s\"", curpath) < 0) + ret = FALSE; + fclose(fp); - } + } else + ret = FALSE; - return TRUE; + return ret; } static int digit_compare(const char *a, const char *b)