summaryrefslogtreecommitdiff
path: root/src/history.c
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-06-11 10:14:53 +0100
committerPhil Jones <philj56@gmail.com>2022-06-11 10:14:53 +0100
commitc0cd4cdf78886040528b16fad084a14165a16384 (patch)
tree82788f09527c91060cea22246f1af9a2572ce655 /src/history.c
parent7c31982244f179cb2f51bb1d81b21ad4efd649ba (diff)
Add compgen caching.
A list of commands is now stored in $XDG_CACHE_HOME/.cache/tofi-compgen, and regenerated as necessary.
Diffstat (limited to 'src/history.c')
-rw-r--r--src/history.c32
1 files changed, 1 insertions, 31 deletions
diff --git a/src/history.c b/src/history.c
index 8cb9eaf..89a45d3 100644
--- a/src/history.c
+++ b/src/history.c
@@ -8,6 +8,7 @@
#include <sys/stat.h>
#include "history.h"
#include "log.h"
+#include "mkdirp.h"
#include "xmalloc.h"
static const char *default_state_dir = ".local/state";
@@ -15,7 +16,6 @@ static const char *histfile_basename = "tofi-history";
[[nodiscard]]
static struct history history_create(void);
-static bool mkdirp(const char *path);
static char *get_histfile_path() {
char *histfile_name = NULL;
@@ -49,7 +49,6 @@ static char *get_histfile_path() {
histfile_basename);
}
return histfile_name;
-
}
struct history history_load()
@@ -193,32 +192,3 @@ void history_remove(struct history *restrict vec, const char *restrict str)
}
}
}
-
-bool mkdirp(const char *path)
-{
- struct stat statbuf;
- if (stat(path, &statbuf) == 0) {
- /* If the history file exists, we don't need to do anything. */
- return true;
- }
-
- /*
- * Walk down the path, creating directories as we go.
- * This works by repeatedly finding the next / in path, then calling
- * mkdir() on the string up to that point.
- */
- char *tmp = xstrdup(path);
- char *cursor = tmp;
- while ((cursor = strchr(cursor + 1, '/')) != NULL) {
- *cursor = '\0';
- log_debug("Creating directory %s\n", tmp);
- if (mkdir(tmp, 0700) != 0 && errno != EEXIST) {
- log_error("Error creating history file path: %s.\n", strerror(errno));
- free(tmp);
- return false;
- }
- *cursor = '/';
- }
- free(tmp);
- return true;
-}