diff options
author | Phil Jones <philj56@gmail.com> | 2022-07-24 12:31:09 +0100 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-07-24 12:40:26 +0100 |
commit | 9e8af9d25106b615dabf956305f4ef80496ed412 (patch) | |
tree | 180ad86a9c1675777c83a9243db5129a01be9146 /src/history.c | |
parent | ee0ed3c506f8f45fce42cbabc1d9521382740924 (diff) |
Add drun mode.
This is a pretty simple implementation, but it should work for most
use cases. Notably, generic application names aren't used (though that
could be added without too much hassle), and neither are keywords (that
would be more difficult).
Diffstat (limited to 'src/history.c')
-rw-r--r-- | src/history.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/history.c b/src/history.c index 7e2a84b..95e7760 100644 --- a/src/history.c +++ b/src/history.c @@ -13,11 +13,18 @@ static const char *default_state_dir = ".local/state"; static const char *histfile_basename = "tofi-history"; +static const char *drun_histfile_basename = "tofi-drun-history"; [[nodiscard("memory leaked")]] static struct history history_create(void); -static char *get_histfile_path() { +static char *get_histfile_path(bool drun) { + const char *basename; + if (drun) { + basename = drun_histfile_basename; + } else { + basename = histfile_basename; + } char *histfile_name = NULL; const char *state_path = getenv("XDG_STATE_HOME"); if (state_path == NULL) { @@ -28,7 +35,7 @@ static char *get_histfile_path() { } size_t len = strlen(home) + 1 + strlen(default_state_dir) + 1 - + strlen(histfile_basename) + 1; + + strlen(basename) + 1; histfile_name = xmalloc(len); snprintf( histfile_name, @@ -36,25 +43,25 @@ static char *get_histfile_path() { "%s/%s/%s", home, default_state_dir, - histfile_basename); + basename); } else { size_t len = strlen(state_path) + 1 - + strlen(histfile_basename) + 1; + + strlen(basename) + 1; histfile_name = xmalloc(len); snprintf( histfile_name, len, "%s/%s", state_path, - histfile_basename); + basename); } return histfile_name; } -struct history history_load() +struct history history_load(bool drun) { struct history vec = history_create(); - char *histfile_name = get_histfile_path(); + char *histfile_name = get_histfile_path(drun); if (histfile_name == NULL) { return vec; } @@ -108,9 +115,9 @@ struct history history_load() return vec; } -void history_save(struct history *history) +void history_save(struct history *history, bool drun) { - char *histfile_name = get_histfile_path(); + char *histfile_name = get_histfile_path(drun); if (histfile_name == NULL) { return; } |