mirror of
https://github.com/Ascyii/nvim.git
synced 2026-01-01 04:04:24 -05:00
Refactor all the custom modules into better structures. Clear separation of keybindings that belong to cusstom modules. Added custom snippets and vsc snippets.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
local M = {}
|
||||
|
||||
local journal_base_raw = "~/management/brainstore/knowledge/journal"
|
||||
local journal_base = vim.fn.expand(journal_base_raw)
|
||||
local journal_base = vim.fn.expand("~/management/brainstore/knowledge/journal")
|
||||
|
||||
M.open_today = function()
|
||||
local date = os.date("*t")
|
||||
239
lua/custom/linker/init.lua
Normal file
239
lua/custom/linker/init.lua
Normal file
@@ -0,0 +1,239 @@
|
||||
local M = {}
|
||||
|
||||
local brainstore_dir = "~/synced/brainstore"
|
||||
local projects_dir = "~/projects"
|
||||
local mail_dir = "~/mail/plain_emails"
|
||||
local contacts_file = "~/synced/vault/contacts/contacts.txt"
|
||||
local cal_dir = "~/synced/brainstore/calendar"
|
||||
|
||||
local function fzf_select(options, prompt, callback)
|
||||
local fzf = require("fzf-lua")
|
||||
fzf.fzf_exec(options, {
|
||||
prompt = prompt .. "> ",
|
||||
actions = {
|
||||
["default"] = function(selected)
|
||||
if selected and selected[1] then
|
||||
callback(selected[1])
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
local function spliting(inputstr, sep)
|
||||
if sep == nil then
|
||||
sep = "%s"
|
||||
end
|
||||
local t = {}
|
||||
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
|
||||
table.insert(t, str)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
local function pad2(n)
|
||||
n = tonumber(n)
|
||||
if n < 10 then
|
||||
return "0" .. n
|
||||
else
|
||||
return tostring(n)
|
||||
end
|
||||
end
|
||||
|
||||
function M.insert_brainstore_link()
|
||||
require('telescope.builtin').find_files({
|
||||
hidden = true,
|
||||
no_ignore = true,
|
||||
follow = true,
|
||||
prompt_title = "Things in Brain",
|
||||
cwd = vim.fn.expand(brainstore_dir),
|
||||
find_command = {
|
||||
"rg", "--files",
|
||||
"--hidden",
|
||||
"--glob", "!**/.git/*",
|
||||
"--glob", "!**/*.{jpg,png,gif,mp4,mkv,tar,zip,iso}",
|
||||
},
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
local actions = require('telescope.actions')
|
||||
local action_state = require('telescope.actions.state')
|
||||
|
||||
local function insert_link()
|
||||
local selection = action_state.get_selected_entry()
|
||||
if not selection then
|
||||
return
|
||||
end
|
||||
local selected = selection.path or selection.filename or selection[1]
|
||||
if selected then
|
||||
actions.close(prompt_bufnr)
|
||||
local link = "[[brain:" .. selected:gsub(vim.fn.expand(brainstore_dir) .. "/", "") .. "]]"
|
||||
vim.cmd("normal! h")
|
||||
vim.api.nvim_put({ link }, "c", true, true)
|
||||
end
|
||||
end
|
||||
|
||||
map('i', '<CR>', insert_link)
|
||||
map('n', '<CR>', insert_link)
|
||||
|
||||
return true
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function M.insert_mail_link()
|
||||
vim.fn.system("python " .. vim.fn.expand("~/projects/scripts/extract_mail.py"))
|
||||
vim.fn.system("find " .. mail_dir .. " -type f > /tmp/mail_files")
|
||||
local mails = vim.fn.readfile("/tmp/mail_files")
|
||||
|
||||
fzf_select(mails, "Mails", function(selected)
|
||||
local link = "[[mail:" .. selected:gsub(vim.fn.expand(mail_dir) .. "/", "") .. "]]"
|
||||
vim.api.nvim_put({ link }, "c", true, true)
|
||||
end)
|
||||
end
|
||||
|
||||
function M.insert_contact_link()
|
||||
local contacts = vim.fn.readfile(vim.fn.expand(contacts_file))
|
||||
|
||||
fzf_select(contacts, "Contacts", function(selected)
|
||||
local name = selected:match("^(.-)%s") or selected -- get first word as contact name
|
||||
local link = "[[contact:" .. name .. "]]"
|
||||
vim.api.nvim_put({ link }, "c", true, true)
|
||||
end)
|
||||
end
|
||||
|
||||
function M.insert_date_link()
|
||||
local year = os.date("%y")
|
||||
local text = string.format("[[date:.%s]]", year)
|
||||
|
||||
vim.api.nvim_put({ text }, "c", true, true)
|
||||
local row, col = table.unpack(vim.api.nvim_win_get_cursor(0))
|
||||
vim.api.nvim_win_set_cursor(0, { row, col - 4 })
|
||||
vim.cmd("startinsert")
|
||||
end
|
||||
|
||||
function M.insert_project_link()
|
||||
require('telescope.builtin').find_files({
|
||||
hidden = true,
|
||||
no_ignore = true,
|
||||
disable_devicons = true,
|
||||
follow = true,
|
||||
prompt_title = "List of projects",
|
||||
cwd = vim.fn.expand(projects_dir),
|
||||
find_command = {
|
||||
"eza", "-1", "-D",
|
||||
},
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
local actions = require('telescope.actions')
|
||||
local action_state = require('telescope.actions.state')
|
||||
|
||||
local function insert_link()
|
||||
local selection = action_state.get_selected_entry()
|
||||
if not selection then
|
||||
return
|
||||
end
|
||||
local selected = selection.path or selection.filename or selection[1]
|
||||
if selected then
|
||||
actions.close(prompt_bufnr)
|
||||
local project = selected:gsub(vim.fn.expand(projects_dir) .. "/", "")
|
||||
|
||||
|
||||
require('telescope.builtin').find_files({
|
||||
hidden = true,
|
||||
no_ignore = true,
|
||||
follow = true,
|
||||
disable_devicons = true,
|
||||
prompt_title = "Pick a file. Press <ESC> to link just " .. project .. ".",
|
||||
cwd = vim.fn.expand(selected),
|
||||
find_command = {
|
||||
"rg", "--files",
|
||||
"--hidden",
|
||||
"--glob", "!**/.git/*",
|
||||
},
|
||||
attach_mappings = function(prompt_bufnr_new, map_new)
|
||||
actions = require('telescope.actions')
|
||||
action_state = require('telescope.actions.state')
|
||||
|
||||
local function insert_link_new()
|
||||
selection = action_state.get_selected_entry()
|
||||
if not selection then
|
||||
return
|
||||
end
|
||||
selected = selection.path or selection.filename or selection[1]
|
||||
if selected then
|
||||
actions.close(prompt_bufnr_new)
|
||||
local link = "[[project:" ..
|
||||
selected:gsub(vim.fn.expand(projects_dir) .. "/", "") .. "]]"
|
||||
vim.api.nvim_put({ link }, "c", true, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function insert_link_top()
|
||||
actions.close(prompt_bufnr_new)
|
||||
local link = "[[project:" .. project .. "]]"
|
||||
vim.api.nvim_put({ link }, "c", true, true)
|
||||
end
|
||||
|
||||
map_new('i', '<CR>', insert_link_new)
|
||||
map_new('n', '<CR>', insert_link_new)
|
||||
|
||||
map_new('i', '<ESC>', insert_link_top)
|
||||
map_new('n', '<ESC>', insert_link_top)
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
map('i', '<CR>', insert_link)
|
||||
map('n', '<CR>', insert_link)
|
||||
|
||||
return true
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function M.follow_link()
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
local link = line:match("%[%[(.-)%]%]")
|
||||
if not link then
|
||||
print("No link found on this line.")
|
||||
return
|
||||
end
|
||||
|
||||
local kind, target = link:match("^(.-):(.*)$")
|
||||
if not kind or not target then
|
||||
print("Invalid link format.")
|
||||
return
|
||||
end
|
||||
|
||||
-- List of all kinds that are available
|
||||
if kind == "brain" then
|
||||
vim.cmd("edit " .. brainstore_dir .. "/" .. target)
|
||||
elseif kind == "mail" then
|
||||
vim.cmd("edit " .. mail_dir .. "/" .. target)
|
||||
elseif kind == "contact" then
|
||||
vim.cmd("vsplit " .. contacts_file)
|
||||
vim.cmd("/" .. target)
|
||||
elseif kind == "project" then
|
||||
vim.cmd("edit " .. projects_dir .. "/" .. target)
|
||||
elseif kind == "date" then
|
||||
-- target: "4.3.25" or "03.04.2034"
|
||||
local splits = spliting(target, '.')
|
||||
local day = pad2(splits[1])
|
||||
local month = pad2(splits[2])
|
||||
local year = splits[3]
|
||||
|
||||
if #year == 4 then
|
||||
year = year:sub(3, 4)
|
||||
end
|
||||
|
||||
vim.cmd("edit " .. cal_dir .. "/calendar_20" .. year .. ".txt")
|
||||
vim.cmd("/" .. "20" .. year .. "-" .. month .. "-" .. day)
|
||||
vim.cmd("normal! zz")
|
||||
else
|
||||
print("Unknown link type: " .. kind .. ".")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -1,6 +1,3 @@
|
||||
-- custom module for todo file editing support in neovim
|
||||
-- inspired by a older plugin that does basically the same
|
||||
|
||||
local M = {}
|
||||
|
||||
local function is_todo_file()
|
||||
@@ -22,7 +19,6 @@ function M.remove_priority()
|
||||
vim.api.nvim_set_current_line(line)
|
||||
end
|
||||
|
||||
|
||||
function M.mark_done()
|
||||
if not is_todo_file() then return end
|
||||
print("Marked todo as done! (just deleted)")
|
||||
@@ -103,22 +99,5 @@ function M.sort_by_project()
|
||||
grouped_sort(get_project_key)
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
for i = string.byte("a"), string.byte("z") do
|
||||
local letter = string.char(i)
|
||||
vim.keymap.set("n", "<leader>p" .. letter, function() M.set_priority(letter) end, opts)
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>p<leader>", M.remove_priority, opts)
|
||||
|
||||
vim.keymap.set("n", "<leader>sp", M.sort_by_priority, opts)
|
||||
vim.keymap.set("n", "<leader>sc", M.sort_by_context, opts)
|
||||
vim.keymap.set("n", "<leader>sr", M.sort_by_project, opts)
|
||||
|
||||
-- New keymap for marking todo as done
|
||||
vim.keymap.set("n", "<leader>td", M.mark_done, opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -6,7 +6,7 @@ local watch_job_id = nil
|
||||
local watch_buf_id = nil
|
||||
local watch_tab_id = nil
|
||||
|
||||
function M.Watch_and_open()
|
||||
function M.watch_and_open()
|
||||
-- Parse the current file and check for typst
|
||||
vim.notify("INIT", vim.log.levels.WARN)
|
||||
local input = vim.fn.expand("%:p")
|
||||
@@ -66,7 +66,7 @@ function M.Watch_and_open()
|
||||
vim.notify("Started Typst watch", vim.log.levels.INFO)
|
||||
|
||||
vim.fn.system("killall .zathura-wrapped")
|
||||
functions.Sleep(0.5)
|
||||
functions.sleep(0.5)
|
||||
vim.fn.jobstart({ "zathura", output }, {
|
||||
on_exit = function()
|
||||
if watch_job_id then
|
||||
@@ -1,9 +1,11 @@
|
||||
local M = {}
|
||||
|
||||
local fzf = require("fzf-lua")
|
||||
local fn = vim.fn
|
||||
local current_season = "S3"
|
||||
local conf = require("conf")
|
||||
|
||||
-- Function to scan for .unicourse files and get their course directories
|
||||
function get_course_directories()
|
||||
function M.get_course_directories()
|
||||
local dirs = {}
|
||||
local function scan_dir(dir)
|
||||
for _, entry in ipairs(fn.glob(dir .. "/*", true, true)) do
|
||||
@@ -26,13 +28,13 @@ function get_course_directories()
|
||||
end
|
||||
end
|
||||
|
||||
scan_dir("~/projects/university/" .. current_season)
|
||||
scan_dir("~/projects/university/" .. conf.season)
|
||||
return dirs
|
||||
end
|
||||
|
||||
-- Function to show the fzf menu for selecting a course directory
|
||||
function select_course_directory()
|
||||
local courses = get_course_directories()
|
||||
function M.select_course_directory()
|
||||
local courses = M.get_course_directories()
|
||||
local course_names = {}
|
||||
|
||||
for _, course in ipairs(courses) do
|
||||
@@ -45,7 +47,7 @@ function select_course_directory()
|
||||
["default"] = function(selected)
|
||||
for _, course in ipairs(courses) do
|
||||
if selected[1] == (course.name .. " (" .. course.short .. ")") then
|
||||
show_course_menu(course)
|
||||
M.show_course_menu(course)
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -55,7 +57,7 @@ function select_course_directory()
|
||||
end
|
||||
|
||||
-- Function to show the fzf menu for actions on a selected course folder
|
||||
function show_course_menu(course)
|
||||
function M.show_course_menu(course)
|
||||
local files = {}
|
||||
-- Collect all VL files in the Vorlesungen directory
|
||||
for _, file in ipairs(fn.glob(course.path .. "/VL/*", true, true)) do
|
||||
@@ -79,10 +81,10 @@ function show_course_menu(course)
|
||||
actions = {
|
||||
["default"] = function(selected)
|
||||
if selected[1] == "Open the newest VL file" then
|
||||
local newest_file = get_newest_vl_file(files)
|
||||
local newest_file = M.get_newest_vl_file(files)
|
||||
vim.cmd("edit " .. newest_file)
|
||||
elseif selected[1] == "Create a new VL" then
|
||||
create_new_vl(course)
|
||||
M.create_new_vl(course)
|
||||
elseif selected[1] == "Open the course folder" then
|
||||
vim.cmd("edit " .. course.path)
|
||||
elseif selected[1] == "Open a specific file" then
|
||||
@@ -101,7 +103,7 @@ function show_course_menu(course)
|
||||
end
|
||||
|
||||
-- Function to get the newest VL file based on modification time
|
||||
function get_newest_vl_file(files)
|
||||
function M.get_newest_vl_file(files)
|
||||
local newest_file = nil
|
||||
local newest_time = 0
|
||||
for _, file in ipairs(files) do
|
||||
@@ -115,18 +117,20 @@ function get_newest_vl_file(files)
|
||||
end
|
||||
|
||||
-- Function to create a new VL file based on the template and incrementing the number
|
||||
function create_new_vl(course)
|
||||
function M.create_new_vl(course)
|
||||
local vl_dir = course.path .. "/VL"
|
||||
local success, _ = pcall(function()
|
||||
pcall(function()
|
||||
vim.fn.mkdir(vl_dir)
|
||||
end)
|
||||
-- Hard coded this
|
||||
local template_path = vim.fn.expand("~/projects/university/data/template.typ")
|
||||
if fn.filereadable(template_path) == 1 then
|
||||
-- Find the latest VL number in the folder
|
||||
--- @type number?
|
||||
local latest_num = 0
|
||||
for _, file in ipairs(fn.glob(vl_dir .. "/*", true, true)) do
|
||||
if file:match(course.short .. "VL(%d+).typ$") then
|
||||
--- @type number?
|
||||
local num = tonumber(file:match(course.short .. "VL(%d+).typ$"))
|
||||
if num > latest_num then
|
||||
latest_num = num
|
||||
@@ -147,3 +151,5 @@ function create_new_vl(course)
|
||||
print("Template file (template.typ) not found!")
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user