mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
it's coming together, update README
This commit is contained in:
82
README.md
82
README.md
@@ -1,5 +1,85 @@
|
||||
# telekasten.nvim
|
||||
|
||||
## Neovim (lua) plugin for markdown zettelkasten, based on telescope.nvim
|
||||
A Neovim (lua) plugin for working with a markdown zettelkasten, based on telescope.nvim
|
||||
|
||||
## Install and setup
|
||||
|
||||
**MS Windows note:** At the moment, telekasten is unlikely to be able to run on Windows, because it relies on a bash script. Just sayin. Since telekasten 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.
|
||||
|
||||
### 1. Install the plugin
|
||||
Install with your plugin manager of choice. Mine is [Vundle](https://github.com/VundleVim/Vundle.vim).
|
||||
|
||||
```vimscript
|
||||
Plugin 'renerocksai/telekasten'
|
||||
```
|
||||
|
||||
### 2. Configure telekasten
|
||||
Somewhere in your vim config, put a snippet like this:
|
||||
|
||||
```vimscript
|
||||
lua << END
|
||||
require('telekasten').setup({
|
||||
home = vim.fn.expand("~/zettelkasten"),
|
||||
dailies = vim.fn.expand("~/zettelkasten/daily"),
|
||||
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
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Install the daily finder
|
||||
Before using telekasten, 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/main/ext_commands/daily_finder.sh):
|
||||
|
||||
```
|
||||
:lua require('telekasten').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
|
||||
|
||||
The plugin defines the following functions.
|
||||
|
||||
- `find_notes()` : find notes by file name (title), via Telescope
|
||||
- `find_daily_notes()` : find daily notes by date (file names, sorted, most recent first), via Telescope
|
||||
- `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 word under cursor and open a Telescope file finder with it: selects note to open (incl. preview)
|
||||
- `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.
|
||||
|
||||
```vimscript
|
||||
:lua require("telekasten").find_daily_notes()
|
||||
```
|
||||
|
||||
## Bind it
|
||||
Usually, you would set up some key bindings, though:
|
||||
|
||||
```vimscript
|
||||
nnoremap <leader>zf :lua require('telekasten').find_notes()
|
||||
nnoremap <leader>zd :lua require('telekasten').find_daily_notes()
|
||||
nnoremap <leader>zg :lua require('telekasten').search_notes()
|
||||
nnoremap <leader>zz :lua require('telekasten').follow_link()
|
||||
|
||||
" note: we define [[ in **insert mode** to call insert link
|
||||
inoremap [[ :lua require('telekasten').insert_link()
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ end
|
||||
--
|
||||
find_daily_notes = function(opts)
|
||||
if (check_local_finder() == true) then
|
||||
print(zkcfg.dailies)
|
||||
builtin.find_files({
|
||||
prompt_title = "Find daily note",
|
||||
cwd = zkcfg.dailies,
|
||||
@@ -113,6 +112,7 @@ follow_link = function(opts)
|
||||
prompt_title = "Follow link to note...",
|
||||
cwd = zkcfg.home,
|
||||
default_text = vim.fn.expand("<cword>"),
|
||||
find_command = { zkcfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
end
|
||||
@@ -123,130 +123,32 @@ end
|
||||
-- Select from notes
|
||||
--
|
||||
find_notes = function(opts)
|
||||
opts = {} or opts
|
||||
|
||||
local find_command = opts.find_command
|
||||
local hidden = opts.hidden
|
||||
local no_ignore = opts.no_ignore
|
||||
local follow = opts.follow
|
||||
local search_dirs = opts.search_dirs
|
||||
|
||||
if search_dirs then
|
||||
for k, v in pairs(search_dirs) do
|
||||
search_dirs[k] = vim.fn.expand(v)
|
||||
end
|
||||
builtin.find_files({
|
||||
prompt_title = "Find notes by name",
|
||||
cwd = zkcfg.home,
|
||||
find_command = { zkcfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
end
|
||||
|
||||
if not find_command then
|
||||
if 1 == vim.fn.executable "fd" then
|
||||
find_command = { "fd", "--type", "f" }
|
||||
if hidden then
|
||||
table.insert(find_command, "--hidden")
|
||||
end
|
||||
if no_ignore then
|
||||
table.insert(find_command, "--no-ignore")
|
||||
end
|
||||
if follow then
|
||||
table.insert(find_command, "-L")
|
||||
end
|
||||
if search_dirs then
|
||||
table.insert(find_command, ".")
|
||||
for _, v in pairs(search_dirs) do
|
||||
table.insert(find_command, v)
|
||||
end
|
||||
end
|
||||
elseif 1 == vim.fn.executable "fdfind" then
|
||||
find_command = { "fdfind", "--type", "f" }
|
||||
if hidden then
|
||||
table.insert(find_command, "--hidden")
|
||||
end
|
||||
if no_ignore then
|
||||
table.insert(find_command, "--no-ignore")
|
||||
end
|
||||
if follow then
|
||||
table.insert(find_command, "-L")
|
||||
end
|
||||
if search_dirs then
|
||||
table.insert(find_command, ".")
|
||||
for _, v in pairs(search_dirs) do
|
||||
table.insert(find_command, v)
|
||||
end
|
||||
end
|
||||
elseif 1 == vim.fn.executable "rg" then
|
||||
find_command = { "rg", "--files" }
|
||||
if hidden then
|
||||
table.insert(find_command, "--hidden")
|
||||
end
|
||||
if no_ignore then
|
||||
table.insert(find_command, "--no-ignore")
|
||||
end
|
||||
if follow then
|
||||
table.insert(find_command, "-L")
|
||||
end
|
||||
if search_dirs then
|
||||
for _, v in pairs(search_dirs) do
|
||||
table.insert(find_command, v)
|
||||
end
|
||||
end
|
||||
elseif 1 == vim.fn.executable "find" and vim.fn.has "win32" == 0 then
|
||||
find_command = { "find", ".", "-type", "f" }
|
||||
if not hidden then
|
||||
table.insert(find_command, { "-not", "-path", "*/.*" })
|
||||
find_command = flatten(find_command)
|
||||
end
|
||||
if no_ignore ~= nil then
|
||||
log.warn "The `no_ignore` key is not available for the `find` command in `find_files`."
|
||||
end
|
||||
if follow then
|
||||
table.insert(find_command, "-L")
|
||||
end
|
||||
if search_dirs then
|
||||
table.remove(find_command, 2)
|
||||
for _, v in pairs(search_dirs) do
|
||||
table.insert(find_command, 2, v)
|
||||
end
|
||||
end
|
||||
elseif 1 == vim.fn.executable "where" then
|
||||
find_command = { "where", "/r", ".", "*" }
|
||||
if hidden ~= nil then
|
||||
log.warn "The `hidden` key is not available for the Windows `where` command in `find_files`."
|
||||
end
|
||||
if no_ignore ~= nil then
|
||||
log.warn "The `no_ignore` key is not available for the Windows `where` command in `find_files`."
|
||||
end
|
||||
if follow ~= nil then
|
||||
log.warn "The `follow` key is not available for the Windows `where` command in `find_files`."
|
||||
end
|
||||
if search_dirs ~= nil then
|
||||
log.warn "The `search_dirs` key is not available for the Windows `where` command in `find_files`."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not find_command then
|
||||
print(
|
||||
"You need to install either find, fd, or rg. "
|
||||
.. "You can also submit a PR to add support for another file finder :)"
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
if opts.cwd then
|
||||
opts.cwd = vim.fn.expand(opts.cwd)
|
||||
end
|
||||
|
||||
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt_title = "Find Files",
|
||||
finder = finders.new_oneshot_job(find_command, opts),
|
||||
previewer = conf.file_previewer(opts),
|
||||
sorter = conf.file_sorter(opts),
|
||||
}):find()
|
||||
--
|
||||
-- search_notes:
|
||||
--
|
||||
-- find the file linked to by the word under the cursor
|
||||
--
|
||||
search_notes = function(opts)
|
||||
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 },
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
--[[
|
||||
-- interesting snippet:
|
||||
function file_exists(name)
|
||||
local f=io.open(name,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
@@ -295,9 +197,9 @@ local M = {
|
||||
zkcfg = zkcfg,
|
||||
find_notes = find_notes,
|
||||
find_daily_notes = find_daily_notes,
|
||||
search_notes = search_notes,
|
||||
insert_link = insert_link,
|
||||
follow_link = follow_link,
|
||||
find_notes = find_filenames,
|
||||
setup = setup,
|
||||
install_daily_finder = install_daily_finder,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user