From 15939f8a6d322e27244fe2f5f57ee51ceb2b5aa1 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Sat, 20 Nov 2021 20:37:28 +0100 Subject: [PATCH] progress --- ext_commands/daily_finder.sh | 49 ++++++++++++++++++++++++++++++++++++ lua/telekasten.lua | 26 ++++++++++++++++--- 2 files changed, 71 insertions(+), 4 deletions(-) create mode 100755 ext_commands/daily_finder.sh diff --git a/ext_commands/daily_finder.sh b/ext_commands/daily_finder.sh new file mode 100755 index 0000000..800878c --- /dev/null +++ b/ext_commands/daily_finder.sh @@ -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 diff --git a/lua/telekasten.lua b/lua/telekasten.lua index bf40ea2..f35e368 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -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(""), 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