forked from lix-project/lix
nix repl: Use $XDG_DATA_HOME for the readline history
This commit is contained in:
parent
921a2aeb05
commit
5bd8795e1f
|
@ -441,6 +441,18 @@ Path getConfigDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Path getDataDir()
|
||||||
|
{
|
||||||
|
Path dataDir = getEnv("XDG_DATA_HOME");
|
||||||
|
if (dataDir.empty()) {
|
||||||
|
Path homeDir = getEnv("HOME");
|
||||||
|
if (homeDir.empty()) throw Error("$XDG_DATA_HOME and $HOME are not set");
|
||||||
|
dataDir = homeDir + "/.local/share";
|
||||||
|
}
|
||||||
|
return dataDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Paths createDirs(const Path & path)
|
Paths createDirs(const Path & path)
|
||||||
{
|
{
|
||||||
Paths created;
|
Paths created;
|
||||||
|
|
|
@ -116,6 +116,9 @@ Path getCacheDir();
|
||||||
/* Return $XDG_CONFIG_HOME or $HOME/.config. */
|
/* Return $XDG_CONFIG_HOME or $HOME/.config. */
|
||||||
Path getConfigDir();
|
Path getConfigDir();
|
||||||
|
|
||||||
|
/* Return $XDG_DATA_HOME or $HOME/.local/share. */
|
||||||
|
Path getDataDir();
|
||||||
|
|
||||||
/* Create a directory and all its parents, if necessary. Returns the
|
/* Create a directory and all its parents, if necessary. Returns the
|
||||||
list of created directories, in order of creation. */
|
list of created directories, in order of creation. */
|
||||||
Paths createDirs(const Path & path);
|
Paths createDirs(const Path & path);
|
||||||
|
|
|
@ -29,9 +29,6 @@ using namespace std;
|
||||||
#define ESC_CYA "\033[36m"
|
#define ESC_CYA "\033[36m"
|
||||||
#define ESC_END "\033[0m"
|
#define ESC_END "\033[0m"
|
||||||
|
|
||||||
string programId = "nix-repl";
|
|
||||||
const string historyFile = string(getenv("HOME")) + "/.nix-repl-history";
|
|
||||||
|
|
||||||
struct NixRepl
|
struct NixRepl
|
||||||
{
|
{
|
||||||
string curDir;
|
string curDir;
|
||||||
|
@ -45,6 +42,8 @@ struct NixRepl
|
||||||
int displ;
|
int displ;
|
||||||
StringSet varNames;
|
StringSet varNames;
|
||||||
|
|
||||||
|
const Path historyFile;
|
||||||
|
|
||||||
StringSet completions;
|
StringSet completions;
|
||||||
StringSet::iterator curCompletion;
|
StringSet::iterator curCompletion;
|
||||||
|
|
||||||
|
@ -115,6 +114,7 @@ string removeWhitespace(string s)
|
||||||
NixRepl::NixRepl(const Strings & searchPath, nix::ref<Store> store)
|
NixRepl::NixRepl(const Strings & searchPath, nix::ref<Store> store)
|
||||||
: state(searchPath, store)
|
: state(searchPath, store)
|
||||||
, staticEnv(false, &state.staticBaseEnv)
|
, staticEnv(false, &state.staticBaseEnv)
|
||||||
|
, historyFile(getDataDir() + "/nix/repl-history")
|
||||||
{
|
{
|
||||||
curDir = absPath(".");
|
curDir = absPath(".");
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,7 @@ void NixRepl::mainLoop(const Strings & files)
|
||||||
// Allow nix-repl specific settings in .inputrc
|
// Allow nix-repl specific settings in .inputrc
|
||||||
rl_readline_name = "nix-repl";
|
rl_readline_name = "nix-repl";
|
||||||
using_history();
|
using_history();
|
||||||
|
createDirs(dirOf(historyFile));
|
||||||
read_history(historyFile.c_str());
|
read_history(historyFile.c_str());
|
||||||
|
|
||||||
string input;
|
string input;
|
||||||
|
|
Loading…
Reference in a new issue