mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 21:36:42 +00:00
Add option to show (non-aut) current session name while saving
This commit is contained in:
parent
0c4a4e2b21
commit
00fb7b6f6b
54
src/nnn.c
54
src/nnn.c
|
@ -484,6 +484,9 @@ static pcre *archive_pcre;
|
||||||
#else
|
#else
|
||||||
static regex_t archive_re;
|
static regex_t archive_re;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef NOSSN
|
||||||
|
static char curssn[NAME_MAX + 1];
|
||||||
|
#endif
|
||||||
|
|
||||||
/* pthread related */
|
/* pthread related */
|
||||||
#define NUM_DU_THREADS (4) /* Can use sysconf(_SC_NPROCESSORS_ONLN) */
|
#define NUM_DU_THREADS (4) /* Can use sysconf(_SC_NPROCESSORS_ONLN) */
|
||||||
|
@ -4487,7 +4490,8 @@ static bool load_session(const char *sname, char **path, char **lastdir, char **
|
||||||
mkpath(cfgpath, toks[TOK_SSN], ssnpath);
|
mkpath(cfgpath, toks[TOK_SSN], ssnpath);
|
||||||
|
|
||||||
if (!restore) {
|
if (!restore) {
|
||||||
sname = sname ? sname : xreadline(NULL, messages[MSG_SSN_NAME]);
|
if (!sname || !sname[0])
|
||||||
|
sname = xreadline(NULL, messages[MSG_SSN_NAME]);
|
||||||
if (!sname[0])
|
if (!sname[0])
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
@ -4538,6 +4542,7 @@ static bool load_session(const char *sname, char **path, char **lastdir, char **
|
||||||
*lastdir = g_ctx[cfg.curctx].c_last;
|
*lastdir = g_ctx[cfg.curctx].c_last;
|
||||||
*lastname = g_ctx[cfg.curctx].c_name;
|
*lastname = g_ctx[cfg.curctx].c_name;
|
||||||
set_sort_flags('\0'); /* Set correct sort options */
|
set_sort_flags('\0'); /* Set correct sort options */
|
||||||
|
xstrsncpy(curssn, sname, NAME_MAX);
|
||||||
status = TRUE;
|
status = TRUE;
|
||||||
|
|
||||||
END:
|
END:
|
||||||
|
@ -6841,7 +6846,7 @@ static void showselsize(const char *path)
|
||||||
printmsg(coolsize(cfg.blkorder ? sz << blk_shift : sz));
|
printmsg(coolsize(cfg.blkorder ? sz << blk_shift : sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool browse(char *ipath, const char *session, int pkey)
|
static bool browse(char *ipath, int pkey)
|
||||||
{
|
{
|
||||||
alignas(max_align_t) char newpath[PATH_MAX];
|
alignas(max_align_t) char newpath[PATH_MAX];
|
||||||
alignas(max_align_t) char runfile[NAME_MAX + 1];
|
alignas(max_align_t) char runfile[NAME_MAX + 1];
|
||||||
|
@ -6867,9 +6872,7 @@ static bool browse(char *ipath, const char *session, int pkey)
|
||||||
|
|
||||||
#ifndef NOSSN
|
#ifndef NOSSN
|
||||||
/* set-up first context */
|
/* set-up first context */
|
||||||
if (!session || !load_session(session, &path, &lastdir, &lastname, FALSE)) {
|
if (!curssn[0] || !load_session(curssn, &path, &lastdir, &lastname, FALSE)) {
|
||||||
#else
|
|
||||||
(void)session;
|
|
||||||
#endif
|
#endif
|
||||||
g_ctx[0].c_last[0] = '\0';
|
g_ctx[0].c_last[0] = '\0';
|
||||||
lastdir = g_ctx[0].c_last; /* last visited directory */
|
lastdir = g_ctx[0].c_last; /* last visited directory */
|
||||||
|
@ -6899,9 +6902,12 @@ static bool browse(char *ipath, const char *session, int pkey)
|
||||||
newpath[0] = runfile[0] = '\0';
|
newpath[0] = runfile[0] = '\0';
|
||||||
|
|
||||||
presel = pkey ? ((pkey == CREATE_NEW_KEY) ? 'n' : ';') : ((cfg.filtermode
|
presel = pkey ? ((pkey == CREATE_NEW_KEY) ? 'n' : ';') : ((cfg.filtermode
|
||||||
|| (session && (g_ctx[cfg.curctx].c_fltr[0] == FILTER
|
#ifndef NOSSN
|
||||||
|
|| (curssn[0] && (g_ctx[cfg.curctx].c_fltr[0] == FILTER
|
||||||
|| g_ctx[cfg.curctx].c_fltr[0] == RFILTER)
|
|| g_ctx[cfg.curctx].c_fltr[0] == RFILTER)
|
||||||
&& g_ctx[cfg.curctx].c_fltr[1])) ? FILTER : 0);
|
&& g_ctx[cfg.curctx].c_fltr[1])
|
||||||
|
#endif
|
||||||
|
) ? FILTER : 0);
|
||||||
|
|
||||||
pdents = xrealloc(pdents, total_dents * sizeof(struct entry));
|
pdents = xrealloc(pdents, total_dents * sizeof(struct entry));
|
||||||
if (!pdents)
|
if (!pdents)
|
||||||
|
@ -8099,7 +8105,8 @@ nochange:
|
||||||
r = get_input(messages[MSG_SSN_OPTS]);
|
r = get_input(messages[MSG_SSN_OPTS]);
|
||||||
|
|
||||||
if (r == 's') {
|
if (r == 's') {
|
||||||
tmp = xreadline(NULL, messages[MSG_SSN_NAME]);
|
tmp = xreadline(!curssn[0] || ((curssn[0] == '@') && !curssn[1]) ? NULL : curssn,
|
||||||
|
messages[MSG_SSN_NAME]);
|
||||||
if (tmp && *tmp)
|
if (tmp && *tmp)
|
||||||
save_session(tmp, &presel);
|
save_session(tmp, &presel);
|
||||||
} else if (r == 'l' || r == 'r') {
|
} else if (r == 'l' || r == 'r') {
|
||||||
|
@ -8629,7 +8636,6 @@ static void cleanup(void)
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *arg = NULL;
|
char *arg = NULL;
|
||||||
char *session = NULL;
|
|
||||||
int fd, opt, sort = 0, pkey = '\0'; /* Plugin key */
|
int fd, opt, sort = 0, pkey = '\0'; /* Plugin key */
|
||||||
bool sepnul = FALSE;
|
bool sepnul = FALSE;
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
|
@ -8766,12 +8772,12 @@ int main(int argc, char *argv[])
|
||||||
#ifndef NOSSN
|
#ifndef NOSSN
|
||||||
case 's':
|
case 's':
|
||||||
if (env_opts_id < 0)
|
if (env_opts_id < 0)
|
||||||
session = optarg;
|
xstrsncpy(curssn, optarg, NAME_MAX);
|
||||||
break;
|
break;
|
||||||
case 'S':
|
case 'S':
|
||||||
g_state.prstssn = 1;
|
g_state.prstssn = 1;
|
||||||
if (!session) /* Support named persistent sessions */
|
if (!curssn[0]) /* Support named persistent sessions */
|
||||||
session = "@";
|
curssn[0] = '@';
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 't':
|
case 't':
|
||||||
|
@ -8834,8 +8840,10 @@ int main(int argc, char *argv[])
|
||||||
} else
|
} else
|
||||||
dup2(STDOUT_FILENO, STDIN_FILENO);
|
dup2(STDOUT_FILENO, STDIN_FILENO);
|
||||||
|
|
||||||
if (session)
|
#ifndef NOSSN
|
||||||
session = NULL;
|
if (curssn[0])
|
||||||
|
curssn[0] = '\0';
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
home = getenv("HOME");
|
home = getenv("HOME");
|
||||||
|
@ -8881,8 +8889,10 @@ int main(int argc, char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session)
|
#ifndef NOSSN
|
||||||
session = NULL;
|
if (curssn[0])
|
||||||
|
curssn[0] = '\0';
|
||||||
|
#endif
|
||||||
} else if (argc == optind) {
|
} else if (argc == optind) {
|
||||||
/* Start in the current directory */
|
/* Start in the current directory */
|
||||||
char *startpath = getenv("PWD");
|
char *startpath = getenv("PWD");
|
||||||
|
@ -8938,8 +8948,10 @@ int main(int argc, char *argv[])
|
||||||
} else if (!S_ISDIR(sb.st_mode))
|
} else if (!S_ISDIR(sb.st_mode))
|
||||||
g_state.initfile = 1;
|
g_state.initfile = 1;
|
||||||
|
|
||||||
if (session)
|
#ifndef NOSSN
|
||||||
session = NULL;
|
if (curssn[0])
|
||||||
|
curssn[0] = '\0';
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9091,11 +9103,11 @@ int main(int argc, char *argv[])
|
||||||
if (sort)
|
if (sort)
|
||||||
set_sort_flags(sort);
|
set_sort_flags(sort);
|
||||||
|
|
||||||
opt = browse(initpath, session, pkey);
|
opt = browse(initpath, pkey);
|
||||||
|
|
||||||
#ifndef NOSSN
|
#ifndef NOSSN
|
||||||
if (session && g_state.prstssn)
|
if (curssn[0] && g_state.prstssn)
|
||||||
save_session(session, NULL);
|
save_session(curssn, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NOMOUSE
|
#ifndef NOMOUSE
|
||||||
|
|
Loading…
Reference in a new issue