commit 26a46f92c1fa15055ef544f3e23d979e66a2c492 Author: Joakim Date: Thu Jan 1 21:46:20 2026 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb07373 --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ + +# Binaries for programs and plugins +jade +jadedepo +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Code coverage profiles and other test artifacts +*.out +coverage.* +*.coverprofile +profile.cov + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env diff --git a/README.md b/README.md new file mode 100644 index 0000000..457dd83 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Notr +Simple [lang: go, lua or other?] application for organizing and referencing notes. Loosly based on obsidian. + +## Workflow +I take notes in two primary ways: +### Phone +- Quick notes, on the go. +- View and search notes. + +### Workstation +- Using NeoVim for notetaking + +### Other infrastructure +- I host a VPS with a Nextcloud and Gitea instances. + +## What I want +- A Obsidian Vault like structure. A folder where notes live. +- A file is a note +- Can also store attachments, such as images. These files can then be referenced in the relevant notes. +- Directories is the main organization method, although tags and links can seam-lesly cross directories boundries. +- Markdown syntax (this can be handled by NeoVim and a markdown editor on other devices.) +- Tags: Syntax +tag +- Note links for referencing other notes or any other vault files. Syntax uncertain. Obsidian uses [[]]? +- See reports about the vault. Tag report +- At some point I would like to have a web-app and host it on my server. This would integrate with my authentik service for auth, and would be a live view of a users vault +- OCR would be great. + +## Implementation +I have a tendency to scope creep and never actually getting a usable product, so an important goal here is practicing getting a usable app up and running. This should not have to be the biggest project, so I'll try to predict the process: + +### Version 0.1 +Here I use other tools for the note-taking and accept that any searching is on a directory basis only. +- [ ] I create a directory in Nextcloud. This I will start using immediately. +- [ ] Find a good Markdown editor for android. +- [ ] Adopt any crutial Obsidian notes + +### Version 1.0 +This is where I can use Notr to find and search notes on my workstation. I think a CLI would be my best bet, although a NeoVim tool could accomplish the same. +- [ ] Process notes. Metadata and diffs +- [ ] Search and Filter by tags +- [ ] Search and Filter by content + +### Version 2.0 +Here I can do the same on my phone. + +Also: +- [ ] OCR + +## Metadata approach +Multiple approaches possible. diff --git a/jade-depo/README.md b/jade-depo/README.md new file mode 100644 index 0000000..7dde652 --- /dev/null +++ b/jade-depo/README.md @@ -0,0 +1,2 @@ +# Jade CLI +The note projects CLI diff --git a/jade-depo/cmd/add.go b/jade-depo/cmd/add.go new file mode 100644 index 0000000..f6427d8 --- /dev/null +++ b/jade-depo/cmd/add.go @@ -0,0 +1,25 @@ +package cmd + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + addCmd = &cobra.Command{ + Short: "Add note to depository", + Use: "add [note]", + Run: addNote, + } +) + +func init() { + rootCmd.AddCommand(addCmd) +} + +func addNote(cmd *cobra.Command, args []string) { + // open new note in $EDITOR + + fmt.Println(args) +} diff --git a/jade-depo/cmd/root.go b/jade-depo/cmd/root.go new file mode 100644 index 0000000..6486e80 --- /dev/null +++ b/jade-depo/cmd/root.go @@ -0,0 +1,42 @@ +package cmd + +import ( + "fmt" + "os" + + "git.jnss.me/joakim/jadedepo/internal/engine" + "github.com/spf13/cobra" +) + +var ( + rootCmd = &cobra.Command{ + Short: "Jade CLI is a note-manager and orchestrator.", + } +) + +var ( + cfgPath string + depoPath string +) + +func init() { + cobra.OnInitialize(func() { + if _, err := engine.Init(cfgPath, depoPath); err != nil { + fmt.Fprintf(os.Stderr, "Error initializing configuration: %v\n", err) + os.Exit(1) + } + }) + + rootCmd.PersistentFlags().StringVar(&cfgPath, "config", "", "Configuration path. Default $HOME/.config/jade") + rootCmd.PersistentFlags().StringVar(&depoPath, "depo", "", "Depository path. Default $HOME/jade-depository") + +} + +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } + + os.Exit(0) +} diff --git a/jade-depo/go.mod b/jade-depo/go.mod new file mode 100644 index 0000000..50aeae8 --- /dev/null +++ b/jade-depo/go.mod @@ -0,0 +1,24 @@ +module git.jnss.me/joakim/jadedepo + +go 1.25.5 + +require ( + github.com/spf13/cobra v1.10.2 + github.com/spf13/viper v1.21.0 +) + +require ( + github.com/fsnotify/fsnotify v1.9.0 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/sagikazarmark/locafero v0.11.0 // indirect + github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect + github.com/spf13/afero v1.15.0 // indirect + github.com/spf13/cast v1.10.0 // indirect + github.com/spf13/pflag v1.0.10 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/text v0.28.0 // indirect +) diff --git a/jade-depo/go.sum b/jade-depo/go.sum new file mode 100644 index 0000000..de19da9 --- /dev/null +++ b/jade-depo/go.sum @@ -0,0 +1,54 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= +github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= +github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.11.0 h1:1iurJgmM9G3PA/I+wWYIOw/5SyBtxapeHDcg+AAIFXc= +github.com/sagikazarmark/locafero v0.11.0/go.mod h1:nVIGvgyzw595SUSUE6tvCp3YYTeHs15MvlmU87WwIik= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 h1:+jumHNA0Wrelhe64i8F6HNlS8pkoyMv5sreGx2Ry5Rw= +github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8/go.mod h1:3n1Cwaq1E1/1lhQhtRK2ts/ZwZEhjcQeJQ1RuC6Q/8U= +github.com/spf13/afero v1.15.0 h1:b/YBCLWAJdFWJTN9cLhiXXcD7mzKn9Dm86dNnfyQw1I= +github.com/spf13/afero v1.15.0/go.mod h1:NC2ByUVxtQs4b3sIUphxK0NioZnmxgyCrfzeuq8lxMg= +github.com/spf13/cast v1.10.0 h1:h2x0u2shc1QuLHfxi+cTJvs30+ZAHOGRic8uyGTDWxY= +github.com/spf13/cast v1.10.0/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= +github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= +github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.21.0 h1:x5S+0EU27Lbphp4UKm1C+1oQO+rKx36vfCoaVebLFSU= +github.com/spf13/viper v1.21.0/go.mod h1:P0lhsswPGWD/1lZJ9ny3fYnVqxiegrlNrEmgLjbTCAY= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= +golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/jade-depo/internal/engine/config.go b/jade-depo/internal/engine/config.go new file mode 100644 index 0000000..5703807 --- /dev/null +++ b/jade-depo/internal/engine/config.go @@ -0,0 +1,97 @@ +package engine + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/spf13/viper" +) + +type Config struct { + // DepoPath is the path to the jade depository. Default ~/jade-depository + DepoPath string `mapstructure:"depo_path"` + // ConfigPath is the path to the config directory. Default ~/.config/jade/config.yml + ConfigPath string `mapstructure:"config_path"` +} + +// getDefaultDepoPath returns the default depository path +func getDefaultDepoPath() string { + home, err := os.UserHomeDir() + if err != nil { + return "./jade-depository" + } + return filepath.Join(home, "jade-depository") +} + +// getDefaultConfigPath returns the default config directory path +func getDefaultConfigPath() string { + home, err := os.UserHomeDir() + if err != nil { + return "./.config/jade/config.yml" + } + return filepath.Join(home, ".config", "jade", "config.yml") +} + +// initConfig initializes the configuration using Viper +// Precedence order: flags > environment variables > config file > defaults +func initConfig(cfgPath, depoPath string) (*Config, error) { + // Set up environment variable support + viper.SetEnvPrefix("JADE") + viper.AutomaticEnv() + + // Set defaults + viper.SetDefault("depo_path", getDefaultDepoPath()) + viper.SetDefault("config_path", getDefaultConfigPath()) + + // Determine config file location + configDir := cfgPath + if configDir == "" { + configDir = getDefaultConfigPath() + } + + // Ensure config directory exists + if err := os.MkdirAll(configDir, 0755); err != nil { + return nil, fmt.Errorf("failed to create config directory: %w", err) + } + + // Set up config file + viper.SetConfigName("config") + viper.SetConfigType("yaml") + viper.AddConfigPath(configDir) + + // Try to read existing config file + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); ok { + // Config file not found, create it with defaults + configFilePath := filepath.Join(configDir, "config.yaml") + if err := viper.SafeWriteConfigAs(configFilePath); err != nil { + return nil, fmt.Errorf("failed to create config file: %w", err) + } + } else { + // Config file was found but another error occurred + return nil, fmt.Errorf("error reading config file: %w", err) + } + } + + // Override with flags if provided (highest precedence) + if depoPath != "" { + viper.Set("depo_path", depoPath) + } + if cfgPath != "" { + viper.Set("config_path", cfgPath) + } + + // Unmarshal config into struct + cfg := &Config{} + if err := viper.Unmarshal(cfg); err != nil { + return nil, fmt.Errorf("failed to unmarshal config: %w", err) + } + + // Write config back to persist any changes (e.g., from flags or env vars) + if err := viper.WriteConfig(); err != nil { + return nil, fmt.Errorf("failed to write config: %w", err) + } + + return cfg, nil +} diff --git a/jade-depo/internal/engine/jade.go b/jade-depo/internal/engine/jade.go new file mode 100644 index 0000000..f427bd2 --- /dev/null +++ b/jade-depo/internal/engine/jade.go @@ -0,0 +1,22 @@ +package engine + +import "fmt" + +type JadeDepo struct { + Config *Config +} + +func Init(cfgPath, depoPath string) (*JadeDepo, error) { + cfg, err := initConfig(cfgPath, depoPath) + if err != nil { + return nil, fmt.Errorf("failed to initialize config: %w", err) + } + + return &JadeDepo{ + Config: cfg, + }, nil +} + +// AddNote creates a new note in the depository +func AddNote() Note { +} diff --git a/jade-depo/internal/engine/note.go b/jade-depo/internal/engine/note.go new file mode 100644 index 0000000..becee34 --- /dev/null +++ b/jade-depo/internal/engine/note.go @@ -0,0 +1,5 @@ +package engine + +type Note struct { + Path string +} diff --git a/jade-depo/main.go b/jade-depo/main.go new file mode 100644 index 0000000..48cea4c --- /dev/null +++ b/jade-depo/main.go @@ -0,0 +1,7 @@ +package main + +import "git.jnss.me/joakim/jadedepo/cmd" + +func main() { + cmd.Execute() +}