mirror of
https://github.com/tomasriveral/NoteWrapper.git
synced 2026-08-12 02:18:38 +02:00
Reworked the building process
This commit is contained in:
@@ -4,3 +4,4 @@ notewrapper
|
|||||||
nw
|
nw
|
||||||
error.log
|
error.log
|
||||||
output.log
|
output.log
|
||||||
|
result/
|
||||||
|
|||||||
@@ -8,16 +8,13 @@ The goal was a terminal-based interface for accessing vaults and notes using sta
|
|||||||
### How to install
|
### How to install
|
||||||
1. Have installed `ncurses`, `cjson`, `make`, `Vivify`, `rsync` and `pkg-config`. <TODO LATER we should put hyprlinks to each program.>
|
1. Have installed `ncurses`, `cjson`, `make`, `Vivify`, `rsync` and `pkg-config`. <TODO LATER we should put hyprlinks to each program.>
|
||||||
2. Have a supported editor: `vim`, `neovim` and `nano` (for the moment)
|
2. Have a supported editor: `vim`, `neovim` and `nano` (for the moment)
|
||||||
3. Clone the repository.
|
3. Clone the repository and enter it.
|
||||||
```shell
|
```shell
|
||||||
git clone https://github.com/Totorile1/NoteWrapper.git
|
git clone https://github.com/Totorile1/NoteWrapper.git
|
||||||
```
|
|
||||||
4. Compile the project. If you are on NixOS and have direnv installed, run `direnv allow`. It will create the nix-shell which will get all the necessary build-time libraries.
|
|
||||||
```
|
|
||||||
cd NoteWrapper
|
cd NoteWrapper
|
||||||
make
|
|
||||||
```
|
```
|
||||||
5. [configure](#configuration) `./config.json`
|
4. Compile the project. On NixOS run `nix-build`. Other OS, run `make`.
|
||||||
|
5. [configure](#configuration) `./config.json` (the file is created on launching, if it already doesn't exist).
|
||||||
6. run the binary `notewrapper`
|
6. run the binary `notewrapper`
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
@@ -56,7 +53,7 @@ The first two features depend on [Vivify's plugin for editors](https://github.co
|
|||||||
| Nano | ❌ | ❌ | ✅ | |
|
| Nano | ❌ | ❌ | ✅ | |
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
Change `~/.config/notewrapper/config.json`. If it does not exist. On building, it should copy a default config.
|
Change `~/.config/notewrapper/config.json`. If it does not exist, the program should create on launch.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
|
||||||
|
pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "notewrapper";
|
||||||
|
version = "1.0";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkgs.pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
pkgs.ncurses
|
||||||
|
pkgs.cjson
|
||||||
|
];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
make
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
cp notewrapper $out/bin/
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with pkgs.lib; {
|
||||||
|
description = " Journaling and notetaking TUI wrapper on top of neovim, vim and nano.";
|
||||||
|
license = licenses.gpl3Only;
|
||||||
|
platforms = platforms.linux;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,52 +1,22 @@
|
|||||||
# Configuration
|
|
||||||
CONFIG_DIR := $(HOME)/.config/notewrapper
|
|
||||||
CONFIG_FILE := $(CONFIG_DIR)/config.json
|
|
||||||
CACHE_DIR := $(HOME)/.cache/notewrapper
|
|
||||||
|
|
||||||
# Compiler and flags
|
|
||||||
CC := gcc
|
CC := gcc
|
||||||
CFLAGS := -Wall -O2 `pkg-config --cflags libcjson ncurses`
|
|
||||||
LDFLAGS := `pkg-config --libs libcjson ncurses`
|
|
||||||
DEBUG ?= 0
|
|
||||||
|
|
||||||
ifeq ($(DEBUG),1)
|
CFLAGS := -Wall -Wextra -O2 \
|
||||||
CFLAGS += -g
|
$(shell pkg-config --cflags libcjson ncurses)
|
||||||
endif
|
|
||||||
|
|
||||||
# Sources and target
|
LDFLAGS := $(shell pkg-config --libs libcjson ncurses)
|
||||||
SRC_DIR := src
|
|
||||||
SRC := $(SRC_DIR)/main.c $(SRC_DIR)/ui.c $(SRC_DIR)/utils.c $(SRC_DIR)/notes.c
|
SRC := src/main.c src/ui.c src/utils.c src/notes.c
|
||||||
TARGET := notewrapper
|
TARGET := notewrapper
|
||||||
|
|
||||||
# Phony targets
|
.PHONY: all run clean
|
||||||
.PHONY: all clean run install_config create_cache_dir
|
|
||||||
|
|
||||||
# Default target
|
all: $(TARGET)
|
||||||
all: install_config create_cache_dir $(TARGET)
|
|
||||||
|
|
||||||
# Build target
|
$(TARGET):
|
||||||
$(TARGET): $(SRC)
|
$(CC) $(CFLAGS) $(SRC) -o $(TARGET) $(LDFLAGS)
|
||||||
@$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
|
||||||
@echo "Built $(TARGET) successfully."
|
|
||||||
|
|
||||||
# Run program
|
|
||||||
run: $(TARGET)
|
run: $(TARGET)
|
||||||
@./$(TARGET)
|
./$(TARGET)
|
||||||
|
|
||||||
# Clean build artifacts
|
|
||||||
clean:
|
clean:
|
||||||
@rm -f $(TARGET)
|
rm -f $(TARGET)
|
||||||
@echo "Cleaned $(TARGET)."
|
|
||||||
|
|
||||||
# Install default config if it does not exist
|
|
||||||
install_config:
|
|
||||||
@mkdir -p $(CONFIG_DIR)
|
|
||||||
@if [ ! -f $(CONFIG_FILE) ]; then \
|
|
||||||
cp ./config.json $(CONFIG_FILE); \
|
|
||||||
echo "config.json installed to $(CONFIG_FILE)"; \
|
|
||||||
else \
|
|
||||||
echo "$(CONFIG_FILE) already exists, skipping installing default config file"; \
|
|
||||||
fi
|
|
||||||
# creates a dir in ~/.cache/ which is used to store data, such as time of last backup
|
|
||||||
create_cache_dir:
|
|
||||||
@mkdir -p $(CACHE_DIR)
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
/nix/store/xcghq18v4yih2bndanbwdrc8n2mgm7yh-notewrapper-1.0
|
||||||
+2
-1
@@ -30,6 +30,7 @@ int main(int argc, char *argv[]) {
|
|||||||
struct passwd *pw = getpwuid(getuid());
|
struct passwd *pw = getpwuid(getuid());
|
||||||
const char *homedir = pw->pw_dir;
|
const char *homedir = pw->pw_dir;
|
||||||
|
|
||||||
|
initAppFilesAndDirs(homedir, shouldDebug);
|
||||||
//---------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------
|
||||||
// this part handles the config.json file
|
// this part handles the config.json file
|
||||||
@@ -44,7 +45,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
// check if the config file exists
|
// check if the config file exists
|
||||||
struct stat st = {0};
|
struct stat st = {0};
|
||||||
error(stat(configPath, &st) == -1, "program", "The config file %s does not exist.\nMaybe try the default path to the config ~/.config/notewrapper/config.json\nOr if you used the flag -c or --config, verifiy that you point to the correct file.\nIf it still does not work, compiling the program with make should create a valid config file in ~/.config/notewrapper.", configPath); // if the config directory does not exist
|
error(stat(configPath, &st) == -1, "user", "The config file %s does not exist.\nMaybe try the default path to the config ~/.config/notewrapper/config.json\nOr if you used the flag -c or --config, verifiy that you point to the correct file.", configPath); // if the config directory does not exist
|
||||||
|
|
||||||
// opens config.json
|
// opens config.json
|
||||||
FILE *f = fopen(configPath, "r");
|
FILE *f = fopen(configPath, "r");
|
||||||
|
|||||||
+54
@@ -91,6 +91,60 @@ void copyDir(const char *source, const char *destination, const int shouldDebug)
|
|||||||
debug("Backup started asynchronously with PID %d\n", pid);
|
debug("Backup started asynchronously with PID %d\n", pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ensureDir(const char *path, const int shouldDebug) {
|
||||||
|
struct stat st = {0};
|
||||||
|
|
||||||
|
if (stat(path, &st) == -1) {
|
||||||
|
debug("Creating the directory %s.", path);
|
||||||
|
error(mkdir(path, 0700) != 0, "program", "mkdir failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void initAppFilesAndDirs(const char *home, const int shouldDebug) {
|
||||||
|
char config_dir[512];
|
||||||
|
char cache_dir[512];
|
||||||
|
|
||||||
|
snprintf(config_dir, sizeof(config_dir),
|
||||||
|
"%s/.config/notewrapper", home);
|
||||||
|
|
||||||
|
snprintf(cache_dir, sizeof(cache_dir),
|
||||||
|
"%s/.cache/notewrapper", home);
|
||||||
|
|
||||||
|
ensureDir(config_dir, shouldDebug);
|
||||||
|
ensureDir(cache_dir, shouldDebug);
|
||||||
|
|
||||||
|
char config_file[512];
|
||||||
|
snprintf(config_file, sizeof(config_file),
|
||||||
|
"%s/config.json", config_dir);
|
||||||
|
|
||||||
|
FILE *f = fopen(config_file, "r");
|
||||||
|
if (f) {
|
||||||
|
fclose(f);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
debug("Creating default config file.");
|
||||||
|
FILE *w = fopen(config_file, "w");
|
||||||
|
error(!w, "program", "fopen failed opening %s");
|
||||||
|
fprintf(w,
|
||||||
|
"{\n"
|
||||||
|
" \"directory\": \"~/Documents/Notes/\",\n"
|
||||||
|
" \"render\": true,\n"
|
||||||
|
" \"jumpToEndOfFileOnLaunch\": true,\n"
|
||||||
|
" \"editor\": \"neovim\",\n"
|
||||||
|
" \"journalRegex\": \".*journal.*\",\n"
|
||||||
|
" \"dateEntry\": \"# %%Y %%m %%d %%a\",\n"
|
||||||
|
" \"newLineOnOpening\": true,\n"
|
||||||
|
" \"backup\": {\n"
|
||||||
|
" \"enable\": false,\n"
|
||||||
|
" \"directory\": \"/path/to/backup\",\n"
|
||||||
|
" \"interval\": \"weekly\"\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
|
||||||
|
fclose(w);
|
||||||
|
}
|
||||||
|
|
||||||
void handleBackups(const char *pathOfVaults, const char *pathOfBackup, const char *homeDir, const int interval, const int shouldDebug) {
|
void handleBackups(const char *pathOfVaults, const char *pathOfBackup, const char *homeDir, const int interval, const int shouldDebug) {
|
||||||
int shouldBackup = 0;
|
int shouldBackup = 0;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ void _error(const int shouldDebug, const int condition, const char *type, const
|
|||||||
// Returns 0 if the string is not in the array.
|
// Returns 0 if the string is not in the array.
|
||||||
// If you want to only check the first n elements of the array, pass n as len.
|
// If you want to only check the first n elements of the array, pass n as len.
|
||||||
int isStringInArray(const char *string, const char **array, const int len);
|
int isStringInArray(const char *string, const char **array, const int len);
|
||||||
|
// initialize the cache directory and creates (if it doesn't already exists) the config file
|
||||||
|
void initAppFilesAndDirs(const char *home, const int shouldDebug);
|
||||||
// returns 1 if the string is in the file.
|
// returns 1 if the string is in the file.
|
||||||
// returns 0 if the string is not in the file.
|
// returns 0 if the string is not in the file.
|
||||||
int isStringInFile(const char *path, const char *string, const int shouldDebug);
|
int isStringInFile(const char *path, const char *string, const int shouldDebug);
|
||||||
|
|||||||
Reference in New Issue
Block a user