This commit is contained in:
Rene Schallner
2021-11-20 20:37:28 +01:00
parent e2aa3c7a00
commit 15939f8a6d
2 changed files with 71 additions and 4 deletions

49
ext_commands/daily_finder.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# daily_finder for telekasten.nvim
#
# gives the plugin the ability to search for daily notes,
# - sorted by date
# - creates today's note if not present, with hardcoded template
# 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
# function DaySuffix:
# little helper to give us st, nd, th for 1st, 2nd, 3rd, 4th, ...
DaySuffix() {
case `date +%d` in
1|21|31) echo "st";;
2|22) echo "nd";;
3|23) echo "rd";;
*) echo "th";;
esac
}
# path to today's note
dailyfile=$the_dir/$(date --iso).md
# function CreateDaily:
# create today's daily note with hardcoded template
CreateDaily() {
daysuffix=$(DaySuffix)
daystr=$(LC_TIME=en_US.UTF-8 date +"%A, %B %d$daysuffix, %Y")
datestr="title: $daystr"
echo --- >> $dailyfile
echo $datestr >> $dailyfile
echo --- >> $dailyfile
}
if [ $(basename $the_dir) = daily ] ; then
if [ ! -f $dailyfile ] ; then
$(CreateDaily)
fi
fi
find $the_dir | sort -rn

View File

@@ -12,7 +12,7 @@ zkcfg = {
home = "/home/rs/zettelkasten", home = "/home/rs/zettelkasten",
dailies = "/home/rs/zettelkasten/daily", dailies = "/home/rs/zettelkasten/daily",
extension = ".md", extension = ".md",
zkfinder = "shitzk.sh", daily_finder = "daily_finder.sh",
} }
@@ -43,7 +43,7 @@ find_daily_notes = function(opts)
builtin.find_files({ builtin.find_files({
prompt_title = "Find daily note", prompt_title = "Find daily note",
cwd = zkcfg.dailies, cwd = zkcfg.dailies,
find_command = { zkcfg.zkfinder }, find_command = { zkcfg.daily_finder },
entry_maker = zk_entry_maker, entry_maker = zk_entry_maker,
}) })
end end
@@ -59,7 +59,6 @@ insert_link = function(opts)
builtin.find_files({ builtin.find_files({
prompt_title = "Insert link to note", prompt_title = "Insert link to note",
cwd = zkcfg.home, cwd = zkcfg.home,
find_command = { zkcfg.zkfinder },
attach_mappings = function(prompt_bufnr, map) attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function() actions.select_default:replace(function()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
@@ -82,7 +81,6 @@ follow_link = function(opts)
builtin.find_files({ builtin.find_files({
prompt_title = "Follow link to note...", prompt_title = "Follow link to note...",
cwd = zkcfg.home, cwd = zkcfg.home,
find_command = { zkcfg.zkfinder },
default_text = vim.fn.expand("<cword>"), default_text = vim.fn.expand("<cword>"),
entry_maker = zk_entry_maker, entry_maker = zk_entry_maker,
}) })
@@ -241,12 +239,32 @@ end
return M return M
--]] --]]
-- 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
--
setup = function(cfg)
cfg = cfg or {}
for k, v in pairs(cfg) do
zkcfg[k] = v
end
end
local M = { local M = {
zkcfg = zkcfg, zkcfg = zkcfg,
find_daily_notes = find_daily_notes, find_daily_notes = find_daily_notes,
insert_link = insert_link, insert_link = insert_link,
follow_link = follow_link, follow_link = follow_link,
find_notes = find_filenames, find_notes = find_filenames,
setup = setup,
} }
print("rene reloaded") print("rene reloaded")
return M return M