mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Fix #1023: support named persistent settions
This commit is contained in:
parent
36e1544b32
commit
54d760b9f5
25
nnn.1
25
nnn.1
|
@ -170,23 +170,26 @@ A new context copies the state of the previous context. Each context can have
|
|||
its own color. See ENVIRONMENT section.
|
||||
.Sh SESSIONS
|
||||
Sessions are a way to save and restore states of work. A session stores the
|
||||
settings and contexts.
|
||||
settings and contexts. Sessions can be loaded at runtime or with a program
|
||||
option.
|
||||
.Pp
|
||||
Sessions can be loaded dynamically at runtime or with a program option.
|
||||
.Pp
|
||||
When a session is loaded dynamically, the last working session is saved
|
||||
automatically to a dedicated -- "last session" -- session file. The "last
|
||||
session" is also used in persistent session mode.
|
||||
.Pp
|
||||
Listing input stream has a higher priority to session options (-s/-S). Sessions
|
||||
can be loaded explicitly at runtime. Session option \fIrestore\fR would restore
|
||||
the persistent session at runtime.
|
||||
- When a session is loaded at runtime, the last working state is saved
|
||||
automatically to a dedicated "auto session" session file. Session option
|
||||
\fIrestore\fR would restore the "auto session".
|
||||
.br
|
||||
- The persistent session option is global. If it is used, the last active session
|
||||
will be updated with the final state at program quit.
|
||||
.br
|
||||
- The "auto session" is used in persistent session mode if no session is active.
|
||||
.br
|
||||
- Listing input stream and opening a bookmark by key have a higher priority to
|
||||
session options (-s/-S).
|
||||
.Pp
|
||||
All the session files are located by session name in the directory
|
||||
.Pp
|
||||
\fB${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions\fR
|
||||
.Pp
|
||||
"@" is the "last session" file.
|
||||
"@" is the "auto session" file.
|
||||
.Sh FILTERS
|
||||
Filters are strings (or regex patterns) to find matching entries in the current
|
||||
directory instantly (\fIsearch-as-you-type\fR). Matches are case-insensitive by
|
||||
|
|
24
src/nnn.c
24
src/nnn.c
|
@ -335,7 +335,8 @@ typedef struct {
|
|||
uint_t stayonsel : 1; /* Disable auto-proceed on select */
|
||||
uint_t dirctx : 1; /* Show dirs in context color */
|
||||
uint_t uidgid : 1; /* Show owner and group info */
|
||||
uint_t reserved : 9; /* Adjust when adding/removing a field */
|
||||
uint_t prstssn : 1; /* Persistent session */
|
||||
uint_t reserved : 8; /* Adjust when adding/removing a field */
|
||||
} runstate;
|
||||
|
||||
/* Contexts or workspaces */
|
||||
|
@ -3851,12 +3852,11 @@ static void savecurctx(settings *curcfg, char *path, char *curname, int nextctx)
|
|||
}
|
||||
|
||||
#ifndef NOSSN
|
||||
static void save_session(bool last_session, int *presel)
|
||||
static void save_session(const char *sname, int *presel)
|
||||
{
|
||||
int i;
|
||||
session_header_t header;
|
||||
FILE *fsession;
|
||||
char *sname;
|
||||
bool status = FALSE;
|
||||
char ssnpath[PATH_MAX];
|
||||
char spath[PATH_MAX];
|
||||
|
@ -3877,10 +3877,6 @@ static void save_session(bool last_session, int *presel)
|
|||
}
|
||||
}
|
||||
|
||||
sname = !last_session ? xreadline(NULL, messages[MSG_SSN_NAME]) : "@";
|
||||
if (!sname[0])
|
||||
return;
|
||||
|
||||
mkpath(cfgpath, toks[TOK_SSN], ssnpath);
|
||||
mkpath(ssnpath, sname, spath);
|
||||
|
||||
|
@ -3942,7 +3938,7 @@ static bool load_session(const char *sname, char **path, char **lastdir, char **
|
|||
mkpath(ssnpath, "@", spath);
|
||||
|
||||
if (has_loaded_dynamically)
|
||||
save_session(TRUE, NULL);
|
||||
save_session("@", NULL);
|
||||
|
||||
fsession = fopen(spath, "rb");
|
||||
if (!fsession) {
|
||||
|
@ -7128,9 +7124,11 @@ nochange:
|
|||
case SEL_SESSIONS:
|
||||
r = get_input(messages[MSG_SSN_OPTS]);
|
||||
|
||||
if (r == 's')
|
||||
if (r == 's') {
|
||||
tmp = xreadline(NULL, messages[MSG_SSN_NAME]);
|
||||
if (tmp && *tmp)
|
||||
save_session(FALSE, &presel);
|
||||
else if (r == 'l' || r == 'r') {
|
||||
} else if (r == 'l' || r == 'r') {
|
||||
if (load_session(NULL, &path, &lastdir, &lastname, r == 'r')) {
|
||||
setdirwatch();
|
||||
goto begin;
|
||||
|
@ -7186,8 +7184,8 @@ nochange:
|
|||
}
|
||||
|
||||
#ifndef NOSSN
|
||||
if (session && *session == '@' && !session[1])
|
||||
save_session(TRUE, NULL);
|
||||
if (session && g_state.prstssn)
|
||||
save_session(session, NULL);
|
||||
#endif
|
||||
|
||||
/* CD on Quit */
|
||||
|
@ -7768,6 +7766,8 @@ int main(int argc, char *argv[])
|
|||
session = optarg;
|
||||
break;
|
||||
case 'S':
|
||||
g_state.prstssn = 1;
|
||||
if (!session) /* Support named persistent sessions */
|
||||
session = "@";
|
||||
break;
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue