Rebrand to log and big haul to makefile

This commit is contained in:
Night Kaly 2024-07-05 10:52:27 +01:00
parent 9edb6b6538
commit 8d140e53cc
Signed by: night0721
GPG key ID: 957D67B8DB7A119B
4 changed files with 99 additions and 100 deletions

View file

@ -1,45 +1,45 @@
CC=gcc .POSIX:
.SUFFIXES:
CC = cc
VERSION = 1.0 VERSION = 1.0
PREFIX = /usr/local TARGET = ccc
MANPREFIX = ${PREFIX}/share/man MANPAGE = $(TARGET).1
CONF = config.h
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
MANDIR = $(PREFIX)/share/man/man1
CFLAGS = -std=gnu11 -O0 -Wall # Flags
CFLAGS = -O3 -march=native -mtune=native -pipe -s -flto -std=c99 -pedantic -Wall -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600
SRC = noted.c config.h SRC = $(TARGET).c
OBJ = ${SRC:.c=.o}
.c.o: $(TARGET): $(SRC) $(CONF)
${CC} -c ${CFLAGS} $< $(CC) $(SRC) -o $@ $(CFLAGS)
noted: ${OBJ} dist: install
${CC} -o $@ ${OBJ} mkdir -p $(TARGET)-$(VERSION)
strip noted cp -R README.md $(MANPAGE) $(TARGET) $(TARGET)-$(VERSION)
tar -cf $(TARGET)-$(VERSION).tar $(TARGET)-$(VERSION)
gzip $(TARGET)-$(VERSION).tar
rm -rf $(TARGET)-$(VERSION)
clean: install: $(TARGET)
rm -rf noted mkdir -p $(DESTDIR)$(BINDIR)
mkdir -p $(DESTDIR)$(MANDIR)
version: cp -p $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)
sed -i 's/#define VERSION "[^"]*"/#define VERSION "${VERSION}"/' config.h chmod 755 $(DESTDIR)$(BINDIR)/$(TARGET)
sed "s/VERSION/${VERSION}/g" < $(MANPAGE) > $(DESTDIR)/$(MANDIR)/$(MANPAGE)
dist: version noted chmod 644 $(DESTDIR)$(MANDIR)/$(MANPAGE)
mkdir -p noted-${VERSION}
cp -R LICENSE README.md noted.1 noted noted-${VERSION}
tar -cf noted-${VERSION}.tar noted-${VERSION}
gzip noted-${VERSION}.tar
rm -rf noted-${VERSION}
install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f noted ${DESTDIR}${PREFIX}/bin
chmod 755 ${DESTDIR}${PREFIX}/bin/noted
mkdir -p ${DESTDIR}${MANPREFIX}/man1
sed "s/VERSION/${VERSION}/g" < noted.1 > ${DESTDIR}${MANPREFIX}/man1/noted.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/noted.1
uninstall: uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/noted\ $(RM) $(DESTDIR)$(BINDIR)/$(TARGET)
${DESTDIR}${MANPREFIX}/man1/noted.1 $(RM) $(DESTDIR)$(MANDIR)/$(MANPAGE)
all: noted
.PHONY: all clean dist install uninstall noted clean:
$(RM) $(TARGET)
all: $(TARGET)
.PHONY: all dist install uninstall clean

View file

@ -1,14 +1,14 @@
# noted # log
noted is a minimalistic command line note manager. log is a minimalistic command line note manager.
# Preview # Preview
![](https://r2.e-z.host/3c62bb3a-a8a9-43f6-afd6-553646f51dc4/lzwqimtg.png) ![](https://r2.e-z.host/3c62bb3a-a8a9-43f6-afd6-553646f51dc4/lzwqimtg.png)
# Usage # Usage
```sh ```sh
Usage: ./noted [-l] [-i] [-v] [-h] Usage: ./log [-l] [-i] [-v] [-h]
./noted [-I|-Q|-R|-S] [filename] ./log [-I|-Q|-R|-S] [filename]
noted is a minimalistic command line note manager written in C. log is a minimalistic command line note manager written in C.
Options: Options:
-l Lists the notes in the directory in a tree format. -l Lists the notes in the directory in a tree format.
-i Prints the directory where the notes are stored. -i Prints the directory where the notes are stored.
@ -30,7 +30,6 @@ Options:
- Generate boilerplate for notes for different formats - Generate boilerplate for notes for different formats
# Dependencies # Dependencies
None None
# Building # Building
@ -41,16 +40,16 @@ $ make
``` ```
# Notes # Notes
noted will use the editor defined in the `EDITOR` environment variable to open notes. If `EDITOR` is not defined, you will need to define it in your shell configuration file. log will use the editor defined in the `EDITOR` environment variable to open notes. If `EDITOR` is not defined, you will need to define it in your shell configuration file.
Default file extension is `.md` and it can be changed in `config.h` file as you like. Once you change the extension, you need to recompile the program to apply the changes and the new notes will have different boilerplates. However, all commands will not work for old notes with the previous extension. Default file extension is `.md` and it can be changed in `config.h` file as you like. Once you change the extension, you need to recompile the program to apply the changes and the new notes will have different boilerplates. However, all commands will not work for old notes with the previous extension.
When adding note, you can add a slash to indicate a subdirectory. For example, `noted -I maths/ch1` will create a note called `ch1` in `maths` folder. **Note**: You can't create a note in a non-existing folder. You need to create the folder first manually. When adding note, you can add a slash to indicate a subdirectory. For example, `log -I maths/ch1` will create a note called `ch1` in `maths` folder. **Note**: You can't create a note in a non-existing folder. You need to create the folder first manually.
Unlike pass, you don't need to use `noted init` to initialise the store, it is automatically created once you use any command. The store is either in HOME or XDG_CONFIG_HOME if it is defined. Unlike pass, you don't need to use `log init` to initialise the store, it is automatically created once you use any command. The store is either in HOME or XDG_CONFIG_HOME if it is defined.
# Contributions # Contributions
Contributions are welcomed, feel free to open a pull request. Contributions are welcomed, feel free to open a pull request.
# License # License
This project is licensed under the GNU Public License v3.0. See [LICENSE](https://github.com/night0721/noted/blob/master/LICENSE) for more information. This project is licensed under the GNU Public License v3.0. See [LICENSE](https://github.com/night0721/log/blob/master/LICENSE) for more information.

View file

@ -1,8 +1,8 @@
.TH noted 1 noted\-VERSION .TH log 1 log\-VERSION
.SH NAME .SH NAME
noted \- Minimalistic note manager log \- Minimalistic note manager
.SH SYNOPSIS .SH SYNOPSIS
.B noted .B log
.RB [ \-l ] .RB [ \-l ]
.RB [ \-i ] .RB [ \-i ]
.RB [ \-v ] .RB [ \-v ]
@ -12,7 +12,7 @@ noted \- Minimalistic note manager
.RB [ \-R ] .RB [ \-R ]
.SH DESCRIPTION .SH DESCRIPTION
noted is a minimalistic command line note manager written in C. It uses EDITOR environment variable to open notes and respects XDG variables to determine the store directory. It also supports markdown and plaintext notes. It is a simple and easy to use note manager with providing basic functionalities like adding, removing, and listing notes. log is a minimalistic command line note manager written in C. It uses EDITOR environment variable to open notes and respects XDG variables to determine the store directory. It also supports markdown and plaintext notes. It is a simple and easy to use note manager with providing basic functionalities like adding, removing, and listing notes.
.SH OPTIONS .SH OPTIONS
.TP .TP

View file

@ -12,31 +12,31 @@
#include "config.h" #include "config.h"
char *get_noted_dir() { char *get_log_dir() {
char *xdg_data_home = getenv("XDG_DATA_HOME"); char *xdg_data_home = getenv("XDG_DATA_HOME");
char *dirname = "noted"; char *dirname = "log";
char *noted_dir = NULL; char *log_dir = NULL;
if (xdg_data_home == NULL) { if (xdg_data_home == NULL) {
xdg_data_home = getenv("HOME"); xdg_data_home = getenv("HOME");
if (xdg_data_home == NULL) { if (xdg_data_home == NULL) {
fprintf(stderr, "noted: HOME and XDG_DATA_HOME environment variable not set\n"); fprintf(stderr, "log: HOME and XDG_DATA_HOME environment variable not set\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
noted_dir = malloc(sizeof(char) * (strlen(xdg_data_home) + strlen(dirname) + 2)); log_dir = malloc(sizeof(char) * (strlen(xdg_data_home) + strlen(dirname) + 2));
if (noted_dir == NULL) { if (log_dir == NULL) {
fprintf(stderr, "noted: Error allocating memory\n"); fprintf(stderr, "log: Error allocating memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
sprintf(noted_dir, "%s/%s", xdg_data_home, dirname); sprintf(log_dir, "%s/%s", xdg_data_home, dirname);
struct stat dir_stat; struct stat dir_stat;
if (!((stat(noted_dir, &dir_stat) == 0) && S_ISDIR(dir_stat.st_mode))) { // check defined path is directory if (!((stat(log_dir, &dir_stat) == 0) && S_ISDIR(dir_stat.st_mode))) { // check defined path is directory
if (mkdir(noted_dir, S_IRWXU)) { // 700 if (mkdir(log_dir, S_IRWXU)) { // 700
fprintf(stderr, "bunker: Cannot create bunker directory\n"); fprintf(stderr, "log: Cannot create log directory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
return noted_dir; return log_dir;
} }
int compare(const void *a, const void *b) { int compare(const void *a, const void *b) {
@ -88,12 +88,12 @@ void tree(const char *basepath, int depth) {
int list_dir(const char *dir) { int list_dir(const char *dir) {
if (dir == NULL || *dir == '\0') { if (dir == NULL || *dir == '\0') {
fprintf(stderr, "noted: Invalid directory path\n"); fprintf(stderr, "log: Invalid directory path\n");
return 1; return 1;
} }
struct stat dir_stat; struct stat dir_stat;
if (stat(dir, &dir_stat) == -1) { if (stat(dir, &dir_stat) == -1) {
perror("noted"); perror("log");
return errno; return errno;
} }
if (S_ISDIR(dir_stat.st_mode)) { if (S_ISDIR(dir_stat.st_mode)) {
@ -101,7 +101,7 @@ int list_dir(const char *dir) {
return 0; return 0;
} else { } else {
fprintf(stderr, "noted: %s is not a directory\n", dir); fprintf(stderr, "log: %s is not a directory\n", dir);
return 1; return 1;
} }
} }
@ -144,22 +144,22 @@ void find_note(const char *basepath, const char *filename, char **filepaths, int
// check if note exists, if yes return the path // check if note exists, if yes return the path
char *check_note_exist(char *filename) { char *check_note_exist(char *filename) {
char *noted_dir = get_noted_dir(); char *log_dir = get_log_dir();
char **file_paths = malloc(sizeof(char *) * 128); // max 128 same file names char **file_paths = malloc(sizeof(char *) * 128); // max 128 same file names
int file_count = 0; int file_count = 0;
find_note(noted_dir, (const char *) filename, file_paths, &file_count); find_note(log_dir, (const char *) filename, file_paths, &file_count);
if (file_count == 0) { if (file_count == 0) {
free(noted_dir); free(log_dir);
return NULL; return NULL;
} else if (file_count == 1) { } else if (file_count == 1) {
char *filepath = malloc(sizeof(char) * (strlen(file_paths[0]) + 1)); char *filepath = malloc(sizeof(char) * (strlen(file_paths[0]) + 1));
if (filepath == NULL) { if (filepath == NULL) {
fprintf(stderr, "noted: Error allocating memory\n"); fprintf(stderr, "log: Error allocating memory\n");
free(noted_dir); free(log_dir);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strcpy(filepath, file_paths[0]); strcpy(filepath, file_paths[0]);
free(noted_dir); free(log_dir);
return filepath; return filepath;
} else { } else {
printf("Multiple files found with the same name:\n"); printf("Multiple files found with the same name:\n");
@ -170,18 +170,18 @@ char *check_note_exist(char *filename) {
int choice; int choice;
scanf("%d", &choice); scanf("%d", &choice);
if (choice < 1 || choice > file_count) { if (choice < 1 || choice > file_count) {
fprintf(stderr, "noted: Invalid choice\n"); fprintf(stderr, "log: Invalid choice\n");
free(noted_dir); free(log_dir);
return NULL; return NULL;
} }
char *filepath = malloc(sizeof(char) * (strlen(file_paths[choice - 1]) + 1)); char *filepath = malloc(sizeof(char) * (strlen(file_paths[choice - 1]) + 1));
if (filepath == NULL) { if (filepath == NULL) {
fprintf(stderr, "noted: Error allocating memory\n"); fprintf(stderr, "log: Error allocating memory\n");
free(noted_dir); free(log_dir);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
strcpy(filepath, file_paths[choice - 1]); strcpy(filepath, file_paths[choice - 1]);
free(noted_dir); free(log_dir);
return filepath; return filepath;
} }
} }
@ -226,19 +226,19 @@ void add_boiler_plate(FILE *file, const char *filename, const char *ext) {
fprintf(file, "\t</body>\n"); fprintf(file, "\t</body>\n");
fprintf(file, "</html>\n"); fprintf(file, "</html>\n");
} else { } else {
fprintf(stderr, "noted: Unsupported file extension\n"); fprintf(stderr, "log: Unsupported file extension\n");
} }
} }
void print_note(char *filename) { void print_note(char *filename) {
if (filename == NULL) { if (filename == NULL) {
fprintf(stderr, "noted: filename is required\n"); fprintf(stderr, "log: filename is required\n");
return; return;
} }
char *filepath = check_note_exist(filename); char *filepath = check_note_exist(filename);
if (filepath != NULL) { if (filepath != NULL) {
FILE *file = fopen(filepath, "r"); FILE *file = fopen(filepath, "r");
if (file == NULL) { if (file == NULL) {
perror("noted"); perror("log");
free(filepath); free(filepath);
return; return;
} }
@ -250,7 +250,7 @@ void print_note(char *filename) {
free(line); free(line);
fclose(file); fclose(file);
} else { } else {
fprintf(stderr, "noted: %s is not in noted\n", filename); fprintf(stderr, "log: %s is not in log\n", filename);
} }
} }
@ -258,14 +258,14 @@ void edit_note(char *filename) {
char *filepath = check_note_exist(filename); char *filepath = check_note_exist(filename);
char *editor = getenv("EDITOR"); char *editor = getenv("EDITOR");
if (editor == NULL) { if (editor == NULL) {
fprintf(stderr, "noted: EDITOR environment variable must be set\n"); fprintf(stderr, "log: EDITOR environment variable must be set\n");
free(filepath); free(filepath);
return; return;
} }
if (filepath != NULL) { if (filepath != NULL) {
char *cmd = malloc(sizeof(char) * (strlen(editor) + strlen(filepath) + 2)); char *cmd = malloc(sizeof(char) * (strlen(editor) + strlen(filepath) + 2));
if (cmd == NULL) { if (cmd == NULL) {
fprintf(stderr, "noted: Error allocating memory\n"); fprintf(stderr, "log: Error allocating memory\n");
free(filepath); free(filepath);
return; return;
} }
@ -273,17 +273,17 @@ void edit_note(char *filename) {
system(cmd); system(cmd);
free(cmd); free(cmd);
} else { } else {
char *noted_dir = get_noted_dir(); char *log_dir = get_log_dir();
filepath = malloc(sizeof(char) * (strlen(noted_dir) + strlen(filename) + 2 + strlen(DEFAULT_EXT))); filepath = malloc(sizeof(char) * (strlen(log_dir) + strlen(filename) + 2 + strlen(DEFAULT_EXT)));
if (filepath == NULL) { if (filepath == NULL) {
fprintf(stderr, "noted: Error allocating memory\n"); fprintf(stderr, "log: Error allocating memory\n");
free(noted_dir); free(log_dir);
return; return;
} }
sprintf(filepath, "%s/%s%s", noted_dir, filename, DEFAULT_EXT); sprintf(filepath, "%s/%s%s", log_dir, filename, DEFAULT_EXT);
FILE *file = fopen(filepath, "w"); FILE *file = fopen(filepath, "w");
if (file == NULL) { if (file == NULL) {
perror("noted"); perror("log");
free(filepath); free(filepath);
return; return;
} }
@ -291,7 +291,7 @@ void edit_note(char *filename) {
fclose(file); fclose(file);
char *cmd = malloc(sizeof(char) * (strlen(editor) + strlen(filepath) + 2)); char *cmd = malloc(sizeof(char) * (strlen(editor) + strlen(filepath) + 2));
if (cmd == NULL) { if (cmd == NULL) {
fprintf(stderr, "noted: Error allocating memory\n"); fprintf(stderr, "log: Error allocating memory\n");
free(filepath); free(filepath);
return; return;
} }
@ -305,12 +305,12 @@ void remove_note(char *filename) {
char *filepath = check_note_exist(filename); char *filepath = check_note_exist(filename);
if (filepath != NULL) { if (filepath != NULL) {
if (remove(filepath) == -1) { if (remove(filepath) == -1) {
perror("noted"); perror("log");
} else { } else {
printf("noted: %s is now removed from noted\n", filename); printf("log: %s is now removed from log\n", filename);
} }
} else { } else {
fprintf(stderr, "noted: %s is not in noted\n", filename); fprintf(stderr, "log: %s is not in log\n", filename);
} }
} }
@ -319,7 +319,7 @@ void search_note(char *filename) {
if (filepath != NULL) { if (filepath != NULL) {
printf("Path of %s: %s\n", filename, filepath); printf("Path of %s: %s\n", filename, filepath);
} else { } else {
fprintf(stderr, "noted: %s is not in noted\n", filename); fprintf(stderr, "log: %s is not in log\n", filename);
} }
} }
@ -330,24 +330,24 @@ void usage(char **argv) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int res; int res;
char *noted_dir = get_noted_dir(); char *log_dir = get_log_dir();
if (noted_dir == NULL) { if (log_dir == NULL) {
return 1; return 1;
} }
if (argc == 2) { if (argc == 2) {
if (strcmp(argv[1], "-l") == 0) { if (strcmp(argv[1], "-l") == 0) {
// read dir and print recursively // read dir and print recursively
res = list_dir(noted_dir); res = list_dir(log_dir);
free(noted_dir); free(log_dir);
return res; return res;
} else if (strcmp(argv[1], "-i") == 0) { } else if (strcmp(argv[1], "-i") == 0) {
printf("noted directory: %s\n", noted_dir); printf("log directory: %s\n", log_dir);
} else if (strcmp(argv[1], "-v") == 0) { } else if (strcmp(argv[1], "-v") == 0) {
printf("noted: %s\n", VERSION); printf("log: %s\n", VERSION);
} else if (strcmp(argv[1], "-h") == 0) { } else if (strcmp(argv[1], "-h") == 0) {
usage(argv); usage(argv);
printf("noted is a minimalistic command line note manager written in C.\n"); printf("log is a minimalistic command line note manager written in C.\n");
printf("Options:\n"); printf("Options:\n");
printf(" -l\t\tLists the notes in the directory in a tree format.\n"); printf(" -l\t\tLists the notes in the directory in a tree format.\n");
printf(" -i\t\tPrints the directory where the notes are stored.\n"); printf(" -i\t\tPrints the directory where the notes are stored.\n");
@ -366,7 +366,7 @@ int main(int argc, char **argv) {
if (argv[2] != NULL && argv[2][0] != '-') { if (argv[2] != NULL && argv[2][0] != '-') {
edit_note(argv[2]); edit_note(argv[2]);
} else { } else {
printf("noted: filename cannot be start with '-'\n"); printf("log: filename cannot be start with '-'\n");
usage(argv); usage(argv);
} }
} else if (strcmp(argv[1], "-Q") == 0) { } else if (strcmp(argv[1], "-Q") == 0) {