@@ 22,6 22,7 @@ Build:
cd szc
meson build
ninja -C build
+ sudo ninja -C build install # To install on system
# Usage
@@ 30,9 31,13 @@ Build:
Then follow along with the prompt.
-Generally provides two modes new and query
+Generally provides three modes: new, query, and link.
-One can create a new hub or zettel. Hubs are simply folders for categorization.
+new can create a new hub or zettel. Hubs are simply folders for categorization.
+
+query can navigate to a zettel.
+
+link can add link tags to two zettels, behaves similarly to query.
zettels are the markdown files in these folders (hubs);
@@ 7,6 7,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
+#include <libgen.h>
void read_zettel(char* filename);
int read_hub(char* hubpath);
@@ 16,6 17,7 @@ void list_hubs(char* zdir);
void user_interface(void);
int get_path(char* path, char* zettel, char* hub);
int scan_zettel(char* path, char* zettel);
+void link_zettel(char* path, char* path2);
void
@@ 175,6 177,16 @@ get_path(char* path, char* zettel, char* hub)
}
void
+link_zettel(char* path, char* path2)
+{
+ FILE* fp = fopen(path, "a");
+ char temp[200];
+ strcpy(temp, path2);
+ fprintf(fp, "link: %s/%s\n", basename(dirname(temp)), basename(temp));
+ fclose(fp);
+}
+
+void
user_interface(void)
{
char zdir[200];
@@ 197,7 209,7 @@ user_interface(void)
}
printf("Hi there! Welcome to Simple Zettelkasten in C.\n");
- printf("Do you want to create a new zettel or query for a zettel?\n");
+ printf("Do you want to create a new zettel, query for a zettel, or link two zettels?\n");
char choice[10];
fgets(choice, 10, stdin);
@@ 216,7 228,7 @@ user_interface(void)
hub[strcspn(hub, "\n")] = '\0';
printf("\n");
- char hubpath[300];
+ char hubpath[300];
strcpy(hubpath, zdir);
strcat(hubpath, hub);
@@ 297,7 309,80 @@ user_interface(void)
} else {
printf("Invalid command: %s. Try hub or zettel\n", choice2);
}
- } else {
+ } else if (strcmp(choice, "link") == 0) {
+
+ printf("Choose first zettel. Listing hubs:\n");
+ list_hubs(zdir);
+ printf("---\n");
+ printf("Select a hub:\n");
+
+ char hub[50];
+ fgets(hub, 50, stdin);
+ hub[strcspn(hub, "\n")] = '\0';
+ printf("\n");
+
+ char hubpath[300];
+ strcpy(hubpath, zdir);
+ strcat(hubpath, hub);
+
+ printf("Listing zettels in hub: %s\n", hub);
+ if (read_hub(hubpath) != 0) {
+ printf("Unable to find hub: %s\n", hub);
+ return;
+ }
+ printf("----\n");
+ printf("Select a zettel by title:\n");
+
+ char zettel[100];
+ fgets(zettel, 100, stdin);
+ zettel[strcspn(zettel, "\n")] = '\0';
+ printf("\n");
+
+ char path[50];
+ if (get_path(path, zettel, hubpath) != 0) {
+ printf("Unable to find zettel: %s\n", zettel);
+ return;
+ }
+
+ printf("Choose second zettel. Listing hubs:\n");
+ list_hubs(zdir);
+ printf("---\n");
+ printf("Select a hub:\n");
+
+ char hub2[50];
+ fgets(hub2, 50, stdin);
+ hub2[strcspn(hub2, "\n")] = '\0';
+ printf("\n");
+
+ char hubpath2[300];
+ strcpy(hubpath2, zdir);
+ strcat(hubpath2, hub2);
+
+ printf("Listing zettels in hub: %s\n", hub2);
+ if (read_hub(hubpath2) != 0) {
+ printf("Unable to find hub: %s\n", hub2);
+ return;
+ }
+ printf("----\n");
+ printf("Select a zettel by title:\n");
+
+ char zettel2[100];
+ fgets(zettel2, 100, stdin);
+ zettel2[strcspn(zettel2, "\n")] = '\0';
+ printf("\n");
+
+ char path2[50];
+ if (get_path(path2, zettel2, hubpath2) != 0) {
+ printf("Unable to find zettel: %s\n", zettel2);
+ return;
+ }
+
+ link_zettel(path, path2);
+ link_zettel(path2, path);
+
+ printf("%s and %s have been linked.\n", zettel, zettel2);
+
+ }else {
printf("Invalid command: %s. Try query or new\n", choice);
}