Skip to content

Commit

Permalink
Add $XDG_STATE_HOME and $HOME/.local/state to list of directories
Browse files Browse the repository at this point in the history
to search for the history file.
  • Loading branch information
gwsw committed Dec 3, 2021
1 parent 2fe1ac8 commit 5e1f4ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
48 changes: 32 additions & 16 deletions cmdbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,14 +1401,41 @@ mlist_size(ml)
/*
* Get the name of the history file.
*/
static char *
histfile_find(must_exist)
int must_exist;
{
char *home = lgetenv("HOME");
char *name = NULL;

/* Try in $XDG_DATA_STATE, then in $HOME/.local/state, then in $XDG_DATA_HOME, then in $HOME. */
#if OS2
if (isnullenv(home))
home = lgetenv("INIT");
#endif
name = dirfile(lgetenv("XDG_STATE_HOME"), &LESSHISTFILE[1], must_exist);
if (name == NULL)
{
char *dir = dirfile(home, ".local/state", 1);
if (dir != NULL)
{
name = dirfile(dir, &LESSHISTFILE[1], must_exist);
free(dir);
}
}
if (name == NULL)
name = dirfile(lgetenv("XDG_DATA_HOME"), &LESSHISTFILE[1], must_exist);
if (name == NULL)
name = dirfile(home, LESSHISTFILE, must_exist);
return (name);
}

static char *
histfile_name(must_exist)
int must_exist;
{
char *home;
char *xdg;
char *name;

/* See if filename is explicitly specified by $LESSHISTFILE. */
name = lgetenv("LESSHISTFILE");
if (!isnullenv(name))
Expand All @@ -1423,25 +1450,14 @@ histfile_name(must_exist)
if (strcmp(LESSHISTFILE, "") == 0 || strcmp(LESSHISTFILE, "-") == 0)
return (NULL);

/* Try in $XDG_DATA_HOME first, then in $HOME. */
xdg = lgetenv("XDG_DATA_HOME");
home = lgetenv("HOME");
#if OS2
if (isnullenv(home))
home = lgetenv("INIT");
#endif
name = NULL;
if (!must_exist)
{
/* If we're writing the file and the file already exists, use it. */
name = dirfile(xdg, &LESSHISTFILE[1], 1);
if (name == NULL)
name = dirfile(home, LESSHISTFILE, 1);
name = histfile_find(1);
}
if (name == NULL)
name = dirfile(xdg, &LESSHISTFILE[1], must_exist);
if (name == NULL)
name = dirfile(home, LESSHISTFILE, must_exist);
name = histfile_find(must_exist);
return (name);
}

Expand Down
6 changes: 3 additions & 3 deletions less.nro.VER
Original file line number Diff line number Diff line change
Expand Up @@ -1976,10 +1976,10 @@ Name of the history file used to remember search commands and
shell commands between invocations of
.IR less .
If set to "\-" or "/dev/null", a history file is not used.
The default is "$XDG_DATA_HOME/lesshst" or "$HOME/.lesshst" on Unix systems,
The default is "$XDG_STATE_HOME/lesshst" or "$HOME/.local/state/lesshst" or
"$XDG_DATA_HOME/lesshst" or "$HOME/.lesshst" on Unix systems,
"$HOME/_lesshst" on DOS and Windows systems,
or "$HOME/lesshst.ini" or "$INIT/lesshst.ini"
on OS/2 systems.
or "$HOME/lesshst.ini" or "$INIT/lesshst.ini" on OS/2 systems.
.IP LESSHISTSIZE
The maximum number of commands to save in the history file.
The default is 100.
Expand Down

0 comments on commit 5e1f4ce

Please sign in to comment.