From 7719111c571c6edd2032abf3c20186f0e205c366 Mon Sep 17 00:00:00 2001 From: nickeb96 Date: Mon, 7 May 2018 17:45:07 -0400 Subject: [PATCH 1/3] Added support for --- src/readline.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/readline.cpp b/src/readline.cpp index ab443ff..4b5aa04 100644 --- a/src/readline.cpp +++ b/src/readline.cpp @@ -70,13 +70,15 @@ public: { rl_readline_name = "sdcv"; using_history(); - const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"; + const gchar *hist_file_str = g_getenv("SDCV_HISTFILE"); + const std::string histname = hist_file_str ? std::string(hist_file_str) : (std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"); read_history(histname.c_str()); } ~real_readline() { - const std::string histname = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"; + const gchar *hist_file_str = g_getenv("SDCV_HISTFILE"); + const std::string histname = hist_file_str ? std::string(hist_file_str) : (std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"); write_history(histname.c_str()); const gchar *hist_size_str = g_getenv("SDCV_HISTSIZE"); int hist_size; From 51f808d96c72506868de5c7be195722516c9784a Mon Sep 17 00:00:00 2001 From: nickeb96 Date: Mon, 7 May 2018 18:02:42 -0400 Subject: [PATCH 2/3] Updated man page --- doc/sdcv.1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/sdcv.1 b/doc/sdcv.1 index 86351b7..d0700e1 100644 --- a/doc/sdcv.1 +++ b/doc/sdcv.1 @@ -89,9 +89,12 @@ If set, sdcv uses this variable as the data directory, this means that sdcv searches dictionaries in $\fBSTARDICT_DATA_DIR\fR\\dic .TP 20 .B SDCV_HISTSIZE -If set, sdcv writes in $(HOME)/.sdcv_history the last $(SDCV_HISTSIZE) words, +If set, sdcv writes in $(HOME)/.sdcv_history (or $(SDCV_HISTFILE)) the last $(SDCV_HISTSIZE) words, which you look up using sdcv. If it is not set, then the last 2000 words are saved in $(HOME)/.sdcv_history. .TP 20 +.B SDCV_HISTFILE +If set, sdcv writes it's history to $(SDCV_HISTFILE). If it is not set, then the default $(HOME)/.sdcv_history path will be used. +.TP 20 .B SDCV_PAGER If SDCV_PAGER is set, its value is used as the name of the program to use to display the dictionary article. From 7341675088672ba9bc20088adfedb7cd0145ccb4 Mon Sep 17 00:00:00 2001 From: nickeb96 Date: Mon, 7 May 2018 20:08:47 -0400 Subject: [PATCH 3/3] Moved history file path code to helper function --- src/readline.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/readline.cpp b/src/readline.cpp index 4b5aa04..f4539b9 100644 --- a/src/readline.cpp +++ b/src/readline.cpp @@ -62,6 +62,16 @@ public: namespace { +std::string get_hist_file_path() +{ + const gchar *hist_file_str = g_getenv("SDCV_HISTFILE"); + + if (hist_file_str != nullptr) + return std::string(hist_file_str); + else + return std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"; +} + class real_readline : public IReadLine { @@ -70,15 +80,13 @@ public: { rl_readline_name = "sdcv"; using_history(); - const gchar *hist_file_str = g_getenv("SDCV_HISTFILE"); - const std::string histname = hist_file_str ? std::string(hist_file_str) : (std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"); + const std::string histname = get_hist_file_path(); read_history(histname.c_str()); } ~real_readline() { - const gchar *hist_file_str = g_getenv("SDCV_HISTFILE"); - const std::string histname = hist_file_str ? std::string(hist_file_str) : (std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"); + const std::string histname = get_hist_file_path(); write_history(histname.c_str()); const gchar *hist_size_str = g_getenv("SDCV_HISTSIZE"); int hist_size;