~emersion/mrsh-dev

history: check for HISTFILE env variable v1 PROPOSED

Merlin: 1
 history: check for HISTFILE env variable

 2 files changed, 19 insertions(+), 3 deletions(-)
- I didn't know about strdup

- I was so blind that I didn't even look for which function calls 
get_history_path, which is defined next to get_history_path and it takes 
state as a parameter
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/mrsh-dev/patches/19589/mbox | git am -3
Learn more about email & git

[PATCH] history: check for HISTFILE env variable Export this patch

if exists and not empty, use its as history file's path.
---
 frontend/readline.c | 19 +++++++++++++++++--
 main.c              |  3 ++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/frontend/readline.c b/frontend/readline.c
index 19880fd..6cb53ec 100644
--- a/frontend/readline.c
+++ b/frontend/readline.c
@@ -38,8 +38,23 @@ static void sigint_handler(int n) {

static char *get_history_path(void) {
	const char *home = getenv("HOME");
	int len = snprintf(NULL, 0, "%s/.mrsh_history", home);
	char *path = malloc(len + 1);
	extern struct mrsh_state *state;
	const char *histfile = mrsh_env_get(state, "HISTFILE", NULL);
	int len;
	char *path;

	if (histfile != NULL && strcmp(histfile, "") != 0) {
		len = strlen(histfile);
		path = malloc(len + 1);
		if (path == NULL) {
			return NULL;
		}
		snprintf(path, len + 1, "%s", histfile);
		return path;
	}

	len = snprintf(NULL, 0, "%s/.mrsh_history", home);
	path = malloc(len + 1);
	if (path == NULL) {
		return NULL;
	}
diff --git a/main.c b/main.c
index 0f433d2..25e278e 100644
--- a/main.c
+++ b/main.c
@@ -15,9 +15,10 @@
#include "frontend.h"

extern char **environ;
struct mrsh_state *state;

int main(int argc, char *argv[]) {
	struct mrsh_state *state = mrsh_state_create();
	state = mrsh_state_create();

	struct mrsh_init_args init_args = {0};
	if (mrsh_process_args(state, &init_args, argc, argv) != 0) {
-- 
2.30.0