mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
refactored! daily finder is gone!
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
# Backlog
|
||||
|
||||
- **!!!!!** recurse subdirs!!!!
|
||||
|
||||
- extend markdown syntax highlights for [[links]]
|
||||
- get rid of `daily_finder.sh`
|
||||
- maybe choose template in create note
|
||||
|
||||
## Dones
|
||||
- [x] get rid of `daily_finder.sh`
|
||||
- [x] find weekly note
|
||||
- [x] goto week
|
||||
- [x] create note, use default template
|
||||
@@ -15,4 +13,3 @@
|
||||
- [x] shortcuts for todo and done in init.vim
|
||||
- [x] Readme search based navigation
|
||||
|
||||
|
||||
|
||||
37
README.md
37
README.md
@@ -15,15 +15,20 @@ I find that pressing the enter key to confirm the search does not interrupt my f
|
||||
|
||||
## Install and setup
|
||||
|
||||
**MS Windows note:** At the moment, telekasten.nvim is unlikely to be able to run on Windows, because it relies on a bash script. Just sayin. Since telekasten.nvim is a project that scratches my own itch, I am not sure if I will add Windows support any time soon. Should anyone read this: Pull requests are welcome 😄! Replacing the daily finder by a proper lua version should do the trick.
|
||||
|
||||
|
||||
### 0. Prerequisites
|
||||
|
||||
#### Telescope
|
||||
Since this plugin uses [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim), you need to install it first.
|
||||
|
||||
[Neovim (v0.5.1)](https://github.com/neovim/neovim/releases/tag/v0.5.1) or the latest neovim nighly commit is required for `telescope.nvim` to work.
|
||||
|
||||
#### Ripgrep
|
||||
For proper sort order of daily notes, the `rg` executable ([Ripgrep](https://github.com/BurntSushi/ripgrep)) is required and needs to be installed so that nvim can find it. So make sure, it's in your path.
|
||||
|
||||
If rg isn't found at `setup()` time, it will not be used. In that case, the sort order of daily and weekly notes are likely to be reversed. I do accept pull requests, though, for a lua implementation 😁!
|
||||
|
||||
|
||||
|
||||
### 1. Install the plugin
|
||||
Install with your plugin manager of choice. Mine is [Vundle](https://github.com/VundleVim/Vundle.vim).
|
||||
@@ -32,6 +37,7 @@ Install with your plugin manager of choice. Mine is [Vundle](https://github.com
|
||||
Plugin 'renerocksai/telekasten.nvim'
|
||||
```
|
||||
|
||||
|
||||
### 2. Configure telekasten.nvim
|
||||
Somewhere in your vim config, put a snippet like this:
|
||||
|
||||
@@ -43,15 +49,6 @@ require('telekasten').setup({
|
||||
dailies = home .. '/' .. 'daily',
|
||||
weeklies = home .. '/' .. 'weekly',
|
||||
extension = ".md",
|
||||
daily_finder = "daily_finder.sh",
|
||||
|
||||
-- where to install the daily_finder,
|
||||
-- (must be a dir in your PATH)
|
||||
my_bin = vim.fn.expand('~/bin'),
|
||||
|
||||
-- download tool for daily_finder installation: curl or wget
|
||||
downloader = 'curl',
|
||||
-- downloader = 'wget', -- wget is supported, too
|
||||
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
@@ -70,16 +67,6 @@ require('telekasten').setup({
|
||||
END
|
||||
```
|
||||
|
||||
### 3. Install the daily finder
|
||||
Before using telekasten.nvim, a shell script needs to be installed. It finds and sorts notes the way we want. As long as I don't have a lua version for this functionality (this is literally the first time I use lua), we will have to stick with `daily_finder.sh`.
|
||||
|
||||
Luckily, the plugin can install the daily finder for you, directly from [GitHub](https://raw.githubusercontent.com/renerocksai/telekasten.nvim/main/ext_commands/daily_finder.sh):
|
||||
|
||||
```
|
||||
:lua require('telekasten.nvim').install_daily_finder()
|
||||
```
|
||||
|
||||
This will download the daily finder into the `bin/` folder of your home directory - or the directory you specified as `my_bin` in the step above.
|
||||
|
||||
## Use it
|
||||
|
||||
@@ -94,7 +81,6 @@ The plugin defines the following functions.
|
||||
- `search_notes()`: live grep for word under cursor in all notes (search in notes), via Telescope
|
||||
- `insert_link()` : select a note by name, via Telescope, and place a `[[link]]` at the current cursor position
|
||||
- `follow_link()`: take text between brackets (linked note) and open a Telescope file finder with it: selects note to open (incl. preview) - with optional note creation for non-existing notes, honoring the configured template
|
||||
- `install_daily_finder()` : installs the daily finder tool used by the plugin
|
||||
- `setup(opts)`: used for configuring paths, file extension, etc.
|
||||
|
||||
To use one of the functions above, just run them with the `:lua ...` command.
|
||||
@@ -200,10 +186,3 @@ Currently, the following things are hardcoded:
|
||||
- the file naming format for daily note files: YYYY-MM-DD.ext (e.g. 2021-11-21.md)
|
||||
- the file naming format for weekly note files: YYYY-Www.ext (e.g. 2021-W46.md)
|
||||
|
||||
Finding and sorting notes is contained in the `daily_finder.sh` script - which you can edit to your liking. I recommend making a copy, though. Otherwise your changes get lost with every plugin update. Don't forget to set `daily_finder = "my_edited_daily_finder.sh"` in the `setup()`, provided you named your copy `my_edited_daily_finder.sh`.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# daily_finder for telekasten.nvim
|
||||
#
|
||||
# actually, this is now the standard finder in telekasten
|
||||
|
||||
if [ "$1" == "check" ] ; then
|
||||
echo OK
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# if called by the plugin, no args are provided, and the current working
|
||||
# directory is set instead
|
||||
if [ "$1" == "" ] ; then
|
||||
the_dir=$(pwd)
|
||||
else
|
||||
the_dir=$1
|
||||
fi
|
||||
|
||||
# sort reversed numerical
|
||||
find $the_dir -type f | sort -rn
|
||||
@@ -1,11 +1,11 @@
|
||||
local builtin = require "telescope.builtin"
|
||||
|
||||
local actions = require("telescope.actions")
|
||||
local action_state = require "telescope.actions.state"
|
||||
local actions = require("telescope.actions") local action_state = require "telescope.actions.state"
|
||||
|
||||
-- declare locals for the nvim api stuff to avoid more lsp warnings
|
||||
local vim = vim
|
||||
|
||||
-- TODO : check if rg exists: vim.fn.executable('rg') - if it isn't, don't set the find_command
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
-- DEFAULT CONFIG
|
||||
@@ -17,15 +17,7 @@ ZkCfg = {
|
||||
dailies = home .. '/' .. 'daily',
|
||||
weeklies = home .. '/' .. 'weekly',
|
||||
extension = ".md",
|
||||
daily_finder = "daily_finder.sh",
|
||||
|
||||
-- where to install the daily_finder,
|
||||
-- (must be a dir in your PATH)
|
||||
my_bin = vim.fn.expand('~/bin'),
|
||||
|
||||
-- download tool for daily_finder installation: curl or wget
|
||||
downloader = 'curl',
|
||||
-- downloader = 'wget', -- wget is supported, too
|
||||
|
||||
-- following a link to a non-existing note will create it
|
||||
follow_creates_nonexisting = true,
|
||||
@@ -40,26 +32,17 @@ ZkCfg = {
|
||||
|
||||
-- ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
local downloader2cmd = {
|
||||
curl = 'curl -o',
|
||||
wget = 'wget -O',
|
||||
}
|
||||
|
||||
local note_type_templates = {
|
||||
normal = ZkCfg.template_new_note,
|
||||
daily = ZkCfg.template_new_daily,
|
||||
weekly = ZkCfg.template_new_weekly,
|
||||
}
|
||||
|
||||
|
||||
local function file_exists(fname)
|
||||
local f=io.open(fname,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
|
||||
local function daysuffix(day)
|
||||
if((day == '1') or (day == '21') or (day == '31')) then return 'st' end
|
||||
if((day == '2') or (day == '22')) then return 'nd' end
|
||||
@@ -67,7 +50,6 @@ local function daysuffix(day)
|
||||
return 'th'
|
||||
end
|
||||
|
||||
|
||||
local function linesubst(line, title)
|
||||
local substs = {
|
||||
date = os.date('%Y-%m-%d'),
|
||||
@@ -83,7 +65,6 @@ local function linesubst(line, title)
|
||||
return line
|
||||
end
|
||||
|
||||
|
||||
local create_note_from_template = function (title, filepath, templatefn)
|
||||
-- first, read the template file
|
||||
local lines = {}
|
||||
@@ -100,7 +81,6 @@ local create_note_from_template = function (title, filepath, templatefn)
|
||||
ofile:close()
|
||||
end
|
||||
|
||||
|
||||
local path_to_linkname = function(p)
|
||||
local fn = vim.split(p, "/")
|
||||
fn = fn[#fn]
|
||||
@@ -110,38 +90,6 @@ local path_to_linkname = function(p)
|
||||
end
|
||||
|
||||
|
||||
local zk_entry_maker = function(entry)
|
||||
return {
|
||||
value = entry,
|
||||
display = path_to_linkname(entry),
|
||||
ordinal = entry,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
local check_local_finder = function()
|
||||
local ret = vim.fn.system(ZkCfg.daily_finder .. ' check')
|
||||
return ret == "OK\n"
|
||||
-- return vim.fn.executable(ZkCfg.daily_finder) == 1
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- InstallDailyFinder:
|
||||
-- -------------------
|
||||
--
|
||||
-- downloads the daily finder scripts to the configured `my_bin` directory
|
||||
-- and makes it executable
|
||||
--
|
||||
InstallDailyFinder = function()
|
||||
local destpath = ZkCfg.my_bin .. '/' .. ZkCfg.daily_finder
|
||||
local cmd = downloader2cmd[ZkCfg.downloader]
|
||||
vim.api.nvim_command('!'.. cmd .. ' ' .. destpath .. ' https://raw.githubusercontent.com/renerocksai/telekasten.nvim/main/ext_commands/daily_finder.sh')
|
||||
vim.api.nvim_command('!chmod +x ' .. destpath)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- FindDailyNotes:
|
||||
-- ---------------
|
||||
@@ -158,20 +106,14 @@ FindDailyNotes = function(opts)
|
||||
create_note_from_template(today, fname, note_type_templates.daily)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Find daily note",
|
||||
cwd = ZkCfg.dailies,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
builtin.find_files({
|
||||
prompt_title = "Find daily note",
|
||||
cwd = ZkCfg.dailies,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- FindWeeklyNotes:
|
||||
-- ---------------
|
||||
@@ -188,20 +130,14 @@ FindWeeklyNotes = function(opts)
|
||||
create_note_from_template(title, fname, note_type_templates.weekly)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Find weekly note",
|
||||
cwd = ZkCfg.weeklies,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
builtin.find_files({
|
||||
prompt_title = "Find weekly note",
|
||||
cwd = ZkCfg.weeklies,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- InsertLink:
|
||||
-- -----------
|
||||
@@ -210,30 +146,24 @@ end
|
||||
--
|
||||
InsertLink = function(opts)
|
||||
opts = {} or opts
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Insert link to note",
|
||||
cwd = ZkCfg.home,
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
map = map -- get rid of lsp error
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
local fn = path_to_linkname(selection.value)
|
||||
vim.api.nvim_put({ "[["..fn.."]]" }, "", false, true)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
builtin.find_files({
|
||||
prompt_title = "Insert link to note",
|
||||
cwd = ZkCfg.home,
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
map = map -- get rid of lsp error
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
local fn = path_to_linkname(selection.value)
|
||||
vim.api.nvim_put({ "[["..fn.."]]" }, "", false, true)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- FollowLink:
|
||||
-- -----------
|
||||
@@ -251,21 +181,15 @@ FollowLink = function(opts)
|
||||
create_note_from_template(title, fname, note_type_templates.normal)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Follow link to note...",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = title,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
builtin.find_files({
|
||||
prompt_title = "Follow link to note...",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = title,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- GotoToday:
|
||||
-- ----------
|
||||
@@ -282,21 +206,15 @@ GotoToday = function(opts)
|
||||
create_note_from_template(word, fname, note_type_templates.daily)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Goto today",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = word,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
builtin.find_files({
|
||||
prompt_title = "Goto today",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = word,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- FindNotes:
|
||||
-- ----------
|
||||
@@ -308,13 +226,11 @@ FindNotes = function(opts)
|
||||
builtin.find_files({
|
||||
prompt_title = "Find notes by name",
|
||||
cwd = ZkCfg.home,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- SearchNotes:
|
||||
-- ------------
|
||||
@@ -324,21 +240,16 @@ end
|
||||
SearchNotes = function(opts)
|
||||
opts = {} or opts
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.live_grep({
|
||||
prompt_title = "Search in notes",
|
||||
cwd = ZkCfg.home,
|
||||
search_dirs = { ZkCfg.home },
|
||||
default_text = vim.fn.expand("<cword>"),
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
builtin.live_grep({
|
||||
prompt_title = "Search in notes",
|
||||
cwd = ZkCfg.home,
|
||||
search_dirs = { ZkCfg.home },
|
||||
default_text = vim.fn.expand("<cword>"),
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- CreateNote:
|
||||
-- ------------
|
||||
@@ -354,18 +265,12 @@ local function on_create(title)
|
||||
create_note_from_template(title, fname, note_type_templates.normal)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Created note...",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = title,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
|
||||
builtin.find_files({
|
||||
prompt_title = "Created note...",
|
||||
cwd = ZkCfg.home,
|
||||
default_text = title,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
CreateNote = function(opts)
|
||||
@@ -374,7 +279,6 @@ CreateNote = function(opts)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- GotoThisWeek:
|
||||
-- ----------
|
||||
@@ -391,36 +295,29 @@ GotoThisWeek = function(opts)
|
||||
create_note_from_template(title, fname, note_type_templates.weekly)
|
||||
end
|
||||
|
||||
if (check_local_finder() == true) then
|
||||
builtin.find_files({
|
||||
prompt_title = "Goto this week:",
|
||||
cwd = ZkCfg.weeklies,
|
||||
default_text = title,
|
||||
find_command = { ZkCfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
else
|
||||
print("Daily finder not found. Try :lua require('telekasten').install_daily_finder()")
|
||||
end
|
||||
builtin.find_files({
|
||||
prompt_title = "Goto this week:",
|
||||
cwd = ZkCfg.weeklies,
|
||||
default_text = title,
|
||||
find_command = ZkCfg.find_command,
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Setup(cfg)
|
||||
--
|
||||
-- Overrides config with elements from cfg
|
||||
-- Valid keys are:
|
||||
-- - home : path to zettelkasten folder
|
||||
-- - dailies : path to folder of daily notes
|
||||
-- - extension : extension of note files (.md)
|
||||
-- - daily_finder: executable that finds daily notes and sorts them by date
|
||||
-- as long as we have no lua equivalent, this will be necessary
|
||||
-- Overrides config with elements from cfg. See top of file for defaults.
|
||||
--
|
||||
Setup = function(cfg)
|
||||
cfg = cfg or {}
|
||||
for k, v in pairs(cfg) do
|
||||
for k, v in pairs(cfg) do
|
||||
ZkCfg[k] = v
|
||||
end
|
||||
end
|
||||
if vim.fn.executable('rg') then
|
||||
ZkCfg.find_command = { 'rg', '--files', '--sortr', 'created', }
|
||||
else
|
||||
ZkCfg.find_command = nil
|
||||
end
|
||||
end
|
||||
|
||||
local M = {
|
||||
@@ -431,7 +328,6 @@ local M = {
|
||||
insert_link = InsertLink,
|
||||
follow_link = FollowLink,
|
||||
setup = Setup,
|
||||
install_daily_finder = InstallDailyFinder,
|
||||
goto_today = GotoToday,
|
||||
new_note = CreateNote,
|
||||
goto_thisweek = GotoThisWeek,
|
||||
|
||||
Reference in New Issue
Block a user