Merge pull request #44 from nickeb96/master

Added $SDCV_HISTFILE to set history file
This commit is contained in:
Evgeniy Dushistov
2018-05-08 03:21:18 +03:00
committed by GitHub
2 changed files with 16 additions and 3 deletions

View File

@@ -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.

View File

@@ -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,13 +80,13 @@ public:
{
rl_readline_name = "sdcv";
using_history();
const std::string histname = 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 std::string histname = 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;