aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md36
-rw-r--r--lua/simple-denote.lua7
-rw-r--r--lua/simple-denote/api.lua1
-rwxr-xr-xlua/simple-denote/scripts/search.sh20
-rw-r--r--lua/simple-denote/search.lua40
5 files changed, 96 insertions, 8 deletions
diff --git a/README.md b/README.md
index 0fc6e8d..cb2e184 100644
--- a/README.md
+++ b/README.md
@@ -11,9 +11,7 @@ For example:
4. `20240601T200121.md`
5. `20240601T213392==1a1--i-have-a-signature__denote_coolstuff.md`
-There is no frontmatter, linking, or any other features. I have overcomplicated my notes too many times with fancy Org Mode and Zettelkasten systems and this is my minimalist endgame.
-
-You can use this on its own or with more featureful plugins like [neorg](https://github.com/nvim-neorg/neorg), [wiki.vim](https://github.com/lervag/wiki.vim), or [Marksman](https://github.com/artempyanykh/marksman), but if your plugin has built in templates you can probably just recreate the denote spec with those instead of using this.
+That's almost this does: open a file. I have overcomplicated my notes too many times with fancy Org Mode and Zettelkasten systems and this is my minimalist endgame. This readme is just overly long to guide any first time Neovim users coming from the Emacs side.
# Installation / Config
@@ -38,10 +36,10 @@ The heading options automatically support Markdown (#) and Org/Norg (*) headings
Maybe you want to set keymaps for the commands as well
```lua
-vim.keymap.set({'n','v'}, '<leader>nn', "<cmd>Denote note<cr>", { desc = "New note" })
-vim.keymap.set({'n','v'}, '<leader>nt', "<cmd>Denote title<cr>", { desc = "Change title" })
-vim.keymap.set({'n','v'}, '<leader>nk', "<cmd>Denote tag<cr>", { desc = "Change tags" })
-vim.keymap.set({'n','v'}, '<leader>nz', "<cmd>Denote signature<cr>", { desc = "Change signature" })
+vim.keymap.set({'n','v'}, '<leader>nn', ":Denote note<cr>", { desc = "New note" })
+vim.keymap.set({'n','v'}, '<leader>nt', ":Denote title<cr>", { desc = "Change title" })
+vim.keymap.set({'n','v'}, '<leader>nk', ":Denote tag<cr>", { desc = "Change tags" })
+vim.keymap.set({'n','v'}, '<leader>nz', ":Denote signature<cr>", { desc = "Change signature" })
```
## Manual Install
@@ -89,12 +87,36 @@ git pull
" Rename the current note with a signature
" This has a user-defined meaning and no particular purpose
:Denote signature
+
+" Built in cursed search command (depends on fzf, fd, and sd)
+:Denote search
+```
+
+# Search
+
+You probably have a separate search plugin you will configure, but there is a cursed a built-in `:Denote search` command that depends on `fzf`, `fd`, and `sd`. It's both reinventing the wheel and WIP.
+
+## Better Alternative: Minimal fzf.vim plugin
+
+Instead of `:Denote search`, you can keep things as fast/minimal as possible by using the built-in `fzf.vim` plugin that comes with `fzf`. This is a barebones wrapper confusingly *not* the same as the identically named `junegunn/fzf.vim` plugin on Github. It's a single file in the `/plugin` directory in the `fzf` repo.
+
+Arch Linux installs it with the `fzf` package under `/usr/share/vim/vimfiles/plugin`. Debian doesn't automatically install it. Find/download and source this file in your `init.lua`:
+
+```lua
+vim.cmd('source /usr/share/vim/vimfiles/plugin/fzf.vim')
+```
+
+Add a keymap to call `:FZF [dir]`:
+
+```lua
+vim.keymap.set({'n','v'}, '<leader>ns', ":FZF ~/notes<cr>", { desc = "Search Notes" })
```
# Credits
* [HumanEntity/denote.nvim](https://github.com/HumanEntity/denote.nvim) - This project was based on denote.nvim and modified to suit my personal preference or closer adhere to the original Denote spec.
* [denote.el](https://protesilaos.com/emacs/denote) - The original Emacs package
+* [Christopher DeLuca](https://www.chrisdeluca.me/2022/01/12/diy-neovim-fzy.html) - Boilerplate code for search function
# License
diff --git a/lua/simple-denote.lua b/lua/simple-denote.lua
index 3f199fe..12ba1f6 100644
--- a/lua/simple-denote.lua
+++ b/lua/simple-denote.lua
@@ -1,7 +1,8 @@
local M = {}
-local api = require("simple-denote.api")
local config = require("simple-denote.config")
+local api = require("simple-denote.api")
+local search = require ("simple-denote.search")
function M.load_cmd(options)
vim.api.nvim_create_user_command("Denote", function(opts)
@@ -13,6 +14,10 @@ function M.load_cmd(options)
api.tag(options)
elseif opts.fargs[1] == "signature" then
api.signature(options)
+ elseif opts.fargs[1] == "search" then
+ search.search(options)
+ elseif opts.fargs[1] == "test" then
+ search.test()
else
error("Unsupported operation " .. opts.fargs[1])
end
diff --git a/lua/simple-denote/api.lua b/lua/simple-denote/api.lua
index 05d645a..36ab8c8 100644
--- a/lua/simple-denote/api.lua
+++ b/lua/simple-denote/api.lua
@@ -1,6 +1,7 @@
local M = {}
local internal = require("simple-denote.internal")
+local search = require ("simple-denote.search")
---@param options table
---@param title string|nil
diff --git a/lua/simple-denote/scripts/search.sh b/lua/simple-denote/scripts/search.sh
new file mode 100755
index 0000000..799e081
--- /dev/null
+++ b/lua/simple-denote/scripts/search.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/sh
+fd . $1 |\
+sd '(?P<prefix>\/.*\/)?(?P<datetime>\d{8}T\d{6})(==(?P<sig>[a-z0-9=]+))?(--(?P<title>[a-z0-9-]+))(__(?P<tags>[a-z0-9_]+))?(?P<ext>\.\w+)' '$prefix|$datetime|$sig|$title|$tags|$ext' |\
+sd '[\=\-\_]' ' ' |\
+sd '(\d{4})(\d{2})(\d{2})(T\d{6})' '$1-$2-$3|$4' |\
+sd '\|\|' '|.|'|\
+column -t -s "|" -N Prefix,Date,Time,Sig,Title,Tags,Ext |\
+fzf --delimiter='\s{2,}' --nth=1..3 --with-nth=2,5,6 --header-lines=1 --reverse --info=hidden --no-separator --preview-window=bottom \
+--preview='
+sig={4}; sig=$(echo $sig | sd "\W" "" | sd " " "="); if [ ! -z ${sig} ] ;then sig="==${sig}"; fi; \
+title={5}; title=$(echo $title | sd " " "-"); if [ ! -z ${title} ] ;then title="--${title}"; fi; \
+tags={6}; tags=$(echo $tags | sd " " "_" | sd "\." ""); if [ ! -z ${tags} ] ;then tags="__${tags}"; fi; \
+ext={7}; \
+echo {1}\|{2}\|{3}\|{4}\|{5}\|{6}\|{7} | sd "(?P<prefix>\/.*\/)?\|(?P<d1>\d\d\d\d)-(?P<d2>\d\d)-(?P<d3>\d\d)\|(?P<time>T\d\d\d\d\d\d)\|.*" "\$prefix\$d1\$d2\$d3\$time$sig$title$tags$ext" | xargs cat' \
+--bind='enter:execute( \
+sig={4}; sig=$(echo $sig | sd "\W" "" | sd " " "="); if [ ! -z ${sig} ] ;then sig="==${sig}"; fi; \
+title={5}; title=$(echo $title | sd " " "-"); if [ ! -z ${title} ] ;then title="--${title}"; fi; \
+tags={6}; tags=$(echo $tags | sd " " "_" | sd "\." ""); if [ ! -z ${tags} ] ;then tags="__${tags}"; fi; \
+ext={7}; \
+echo {1}\|{2}\|{3}\|{4}\|{5}\|{6}\|{7} | sd "(?P<prefix>\/.*\/)?\|(?P<d1>\d\d\d\d)-(?P<d2>\d\d)-(?P<d3>\d\d)\|(?P<time>T\d\d\d\d\d\d)\|.*" "\$prefix\$d1\$d2\$d3\$time$sig$title$tags$ext" | cat)+abort'
diff --git a/lua/simple-denote/search.lua b/lua/simple-denote/search.lua
new file mode 100644
index 0000000..eab25dd
--- /dev/null
+++ b/lua/simple-denote/search.lua
@@ -0,0 +1,40 @@
+local M = {}
+
+function M.search(options)
+ local width = vim.o.columns - 8
+ local height = vim.o.lines - 8
+
+ vim.api.nvim_open_win(
+ vim.api.nvim_create_buf(false, true),
+ true,
+ {
+ relative = 'editor',
+ style = 'minimal',
+ border = 'rounded',
+ noautocmd = true,
+ width = width,
+ height = height,
+ col = math.min((vim.o.columns - width) / 2),
+ row = math.min((vim.o.lines - height) / 2 - 1),
+ }
+ )
+ local file = vim.fn.tempname()
+ -- This feels like the wrong way to call a script from a relative path
+ local lua_file_path = debug.getinfo(1, "S").source:sub(2)
+ local lua_file_dir = vim.fn.fnamemodify(lua_file_path, ":h")
+ local script_path = lua_file_dir .. "/scripts/search.sh"
+ if not script_path then
+ error("Script not found")
+ end
+ vim.api.nvim_command('startinsert')
+ vim.fn.termopen(script_path .. " " .. options.dir .. " > " .. file, {
+ on_exit = function(jobid, data, event)
+ vim.api.nvim_command('bdelete!')
+ local f = io.open(file, 'r')
+ local stdout = f:read('*all')
+ f:close()
+ os.remove(file)
+ vim.api.nvim_command('edit ' .. stdout)
+ end})
+end
+return M