From 68991673c0b14f99f857881a4f29a2f303ab993a Mon Sep 17 00:00:00 2001 From: Tomas Rivera Date: Sun, 26 Apr 2026 21:00:20 +0200 Subject: [PATCH] fix: expands \~ to the home directory inside "directory" in the config file --- src/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 383de91..dd2f127 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,7 @@ #include "ui.h" #include "utils.h" #include "notes.h" +#include int main(int argc, char *argv[]) { int shouldDebug = 0; @@ -114,8 +115,16 @@ arg_next: int i = 0; cJSON_ArrayForEach(tempEntry, dirJson) { // iterate over all the elements of the array _i. e._ over all the dirs if (tempEntry && cJSON_IsString(tempEntry)) { - directoriesArray[i] = strdup(cJSON_GetStringValue(tempEntry)); - altDebug("%s\n",directoriesArray[i]); + if (cJSON_GetStringValue(tempEntry)[0] == '~') { // we must expand ~ + char *tempUnFixedName = cJSON_GetStringValue(tempEntry); + tempUnFixedName++; // shifts and removes the ~ + directoriesArray[i] = malloc(PATH_MAX); + debug("~ in %s was expanded to %s", tempUnFixedName, homedir); + snprintf(directoriesArray[i], PATH_MAX, "%s/%s", homedir, tempUnFixedName); + } else { + directoriesArray[i] = strdup(cJSON_GetStringValue(tempEntry)); + altDebug("%s\n",directoriesArray[i]); + } } else { error(1, "user", "In %s, in \"directory\", invalid type of one of the entries.", configPath); }