mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 14:14:24 -05:00
progress
This commit is contained in:
49
ext_commands/daily_finder.sh
Executable file
49
ext_commands/daily_finder.sh
Executable 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
|
||||
@@ -12,7 +12,7 @@ zkcfg = {
|
||||
home = "/home/rs/zettelkasten",
|
||||
dailies = "/home/rs/zettelkasten/daily",
|
||||
extension = ".md",
|
||||
zkfinder = "shitzk.sh",
|
||||
daily_finder = "daily_finder.sh",
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ find_daily_notes = function(opts)
|
||||
builtin.find_files({
|
||||
prompt_title = "Find daily note",
|
||||
cwd = zkcfg.dailies,
|
||||
find_command = { zkcfg.zkfinder },
|
||||
find_command = { zkcfg.daily_finder },
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
end
|
||||
@@ -59,7 +59,6 @@ insert_link = function(opts)
|
||||
builtin.find_files({
|
||||
prompt_title = "Insert link to note",
|
||||
cwd = zkcfg.home,
|
||||
find_command = { zkcfg.zkfinder },
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
@@ -82,7 +81,6 @@ follow_link = function(opts)
|
||||
builtin.find_files({
|
||||
prompt_title = "Follow link to note...",
|
||||
cwd = zkcfg.home,
|
||||
find_command = { zkcfg.zkfinder },
|
||||
default_text = vim.fn.expand("<cword>"),
|
||||
entry_maker = zk_entry_maker,
|
||||
})
|
||||
@@ -241,12 +239,32 @@ end
|
||||
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 = {
|
||||
zkcfg = zkcfg,
|
||||
find_daily_notes = find_daily_notes,
|
||||
insert_link = insert_link,
|
||||
follow_link = follow_link,
|
||||
find_notes = find_filenames,
|
||||
setup = setup,
|
||||
}
|
||||
print("rene reloaded")
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user