mirror of
https://github.com/Ascyii/nvim.git
synced 2026-01-01 04:04:24 -05:00
Init from other configuration repository. This is just a backup and will be refactored soon
This commit is contained in:
66
lua/custom/journal.lua
Normal file
66
lua/custom/journal.lua
Normal file
@@ -0,0 +1,66 @@
|
||||
local M = {}
|
||||
|
||||
local journal_base_raw = "~/management/brainstore/knowledge/journal"
|
||||
local journal_base = vim.fn.expand(journal_base_raw)
|
||||
|
||||
M.open_today = function()
|
||||
local date = os.date("*t")
|
||||
local day = os.date("%d")
|
||||
local month = os.date("%m")
|
||||
local year = tostring(date.year)
|
||||
|
||||
-- Define the filename and full path
|
||||
local filename = string.format("%s.%s.md", day, month)
|
||||
local full_path = string.format("%s/%s/%s", journal_base, year, filename)
|
||||
|
||||
-- Create the year folder if it doesn't exist
|
||||
vim.fn.system({ "mkdir", "-p", journal_base .. "/" .. year })
|
||||
|
||||
-- Check if the file exists and create it if not
|
||||
local file = io.open(full_path, "r")
|
||||
if not file then
|
||||
-- If the file does not exist, create and write the header
|
||||
local header = string.format("# Journal Entry - [[date:%s]]\n\n", os.date("%d.%m.%y"))
|
||||
file = io.open(full_path, "w")
|
||||
file:write(header)
|
||||
file:close()
|
||||
end
|
||||
|
||||
-- Open the file for editing
|
||||
vim.cmd("edit " .. full_path)
|
||||
vim.cmd("normal! G")
|
||||
end
|
||||
|
||||
|
||||
M.search_this_month = function()
|
||||
local date = os.date("*t")
|
||||
|
||||
local month = os.date("%m")
|
||||
local year = tostring(date.year)
|
||||
|
||||
local path = string.format("%s/%s", journal_base, year)
|
||||
|
||||
-- Use telescope or fzf-lua
|
||||
require('telescope.builtin').find_files {
|
||||
prompt_title = "Journal Entries This Month",
|
||||
cwd = path,
|
||||
find_command = {
|
||||
"rg", "--files", "--glob", "*.md", "-e", string.format("^\\d\\d.%s.md", month)
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
M.list_all_journals = function()
|
||||
-- Use telescope or fzf-lua
|
||||
require('telescope.builtin').find_files {
|
||||
prompt_title = "All Journal Entries",
|
||||
cwd = journal_base, -- Start from the base folder
|
||||
find_command = {
|
||||
"rg", "--files", "--glob", "*/??.??.md",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
140
lua/custom/todo.lua
Normal file
140
lua/custom/todo.lua
Normal file
@@ -0,0 +1,140 @@
|
||||
-- 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()
|
||||
return vim.fn.expand("%:t") == "todo.txt"
|
||||
end
|
||||
|
||||
function M.set_priority(letter)
|
||||
if not is_todo_file() then return end
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
line = line:gsub("^%(%u%)%s*", "")
|
||||
vim.api.nvim_set_current_line(string.format("(%s) %s", letter:upper(), line))
|
||||
end
|
||||
|
||||
-- Remove priority
|
||||
function M.remove_priority()
|
||||
if not is_todo_file() then return end
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
line = line:gsub("^%(%u%)%s*", "")
|
||||
vim.api.nvim_set_current_line(line)
|
||||
end
|
||||
|
||||
local function strip_ansi(s)
|
||||
return s:gsub("\27%[[0-9;]*m", "")
|
||||
end
|
||||
|
||||
function M.mark_done()
|
||||
if not is_todo_file() then return end
|
||||
|
||||
--local line = vim.api.nvim_get_current_line():match("^%s*(.-)%s*$")
|
||||
|
||||
--local tasks = vim.fn.systemlist("todo.sh list")
|
||||
--for _, task in ipairs(tasks) do
|
||||
-- --
|
||||
-- local num,_, desc = task:match("^(%d+)%s(?:%(%S%)%s+)?(.+)$")
|
||||
-- if desc == line then
|
||||
-- id = num
|
||||
-- break
|
||||
-- end
|
||||
--end
|
||||
|
||||
print("Marked todo as done! (just deleted)")
|
||||
vim.cmd("normal! dd")
|
||||
end
|
||||
|
||||
-- Util: remove empty lines
|
||||
local function strip_blank_lines(lines)
|
||||
local cleaned = {}
|
||||
for _, line in ipairs(lines) do
|
||||
if line:match("%S") then
|
||||
table.insert(cleaned, line)
|
||||
end
|
||||
end
|
||||
return cleaned
|
||||
end
|
||||
|
||||
-- Grouped sort logic
|
||||
local function grouped_sort(key_fn)
|
||||
if not is_todo_file() then return end
|
||||
local lines = strip_blank_lines(vim.api.nvim_buf_get_lines(0, 0, -1, false))
|
||||
local buckets = {}
|
||||
|
||||
for _, line in ipairs(lines) do
|
||||
local key = key_fn(line)
|
||||
if not buckets[key] then
|
||||
buckets[key] = {}
|
||||
end
|
||||
table.insert(buckets[key], line)
|
||||
end
|
||||
|
||||
local sorted_keys = {}
|
||||
for key in pairs(buckets) do table.insert(sorted_keys, key) end
|
||||
table.sort(sorted_keys)
|
||||
|
||||
local final_lines = {}
|
||||
for _, key in ipairs(sorted_keys) do
|
||||
for _, line in ipairs(buckets[key]) do
|
||||
table.insert(final_lines, line)
|
||||
end
|
||||
table.insert(final_lines, "") -- add blank line after group
|
||||
end
|
||||
|
||||
-- Remove final blank line if it exists
|
||||
if final_lines[#final_lines] == "" then
|
||||
table.remove(final_lines)
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, final_lines)
|
||||
end
|
||||
|
||||
-- Key extractors
|
||||
local function get_priority_key(line)
|
||||
local p = line:match("^%((%u)%)")
|
||||
return p and p or "~" -- tilde = sorts after all letters
|
||||
end
|
||||
|
||||
local function get_context_key(line)
|
||||
local c = line:match("@(%w+)")
|
||||
return c and c or "~"
|
||||
end
|
||||
|
||||
local function get_project_key(line)
|
||||
local p = line:match("%+(%w+)")
|
||||
return p and p or "~"
|
||||
end
|
||||
|
||||
-- Sorters
|
||||
function M.sort_by_priority()
|
||||
grouped_sort(get_priority_key)
|
||||
end
|
||||
|
||||
function M.sort_by_context()
|
||||
grouped_sort(get_context_key)
|
||||
end
|
||||
|
||||
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
|
||||
151
lua/custom/uni.lua
Normal file
151
lua/custom/uni.lua
Normal file
@@ -0,0 +1,151 @@
|
||||
local fzf = require("fzf-lua")
|
||||
local fn = vim.fn
|
||||
local uv = vim.loop
|
||||
local current_season = "S3"
|
||||
|
||||
-- Function to scan for .unicourse files and get their course directories
|
||||
function get_course_directories()
|
||||
local dirs = {}
|
||||
local function scan_dir(dir)
|
||||
for _, entry in ipairs(fn.glob(dir .. "/*", true, true)) do
|
||||
if fn.isdirectory(entry) == 1 then
|
||||
local unicourse_file = entry .. "/.unicourse"
|
||||
if fn.filereadable(unicourse_file) == 1 then
|
||||
local course_info = {}
|
||||
for line in io.lines(unicourse_file) do
|
||||
if line:match("^name: ") then
|
||||
course_info.name = line:sub(7)
|
||||
elseif line:match("^short: ") then
|
||||
course_info.short = line:sub(8)
|
||||
end
|
||||
end
|
||||
if course_info.name and course_info.short then
|
||||
table.insert(dirs, { name = course_info.name, short = course_info.short, path = entry })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scan_dir("/home/jonas/projects/university/" .. current_season) -- Assuming all your courses are under the S2 folder
|
||||
return dirs
|
||||
end
|
||||
|
||||
-- Function to show the fzf menu for selecting a course directory
|
||||
function select_course_directory()
|
||||
local courses = get_course_directories()
|
||||
local course_names = {}
|
||||
|
||||
for _, course in ipairs(courses) do
|
||||
table.insert(course_names, course.name .. " (" .. course.short .. ")")
|
||||
end
|
||||
|
||||
fzf.fzf_exec(course_names, {
|
||||
prompt = "Select a course > ",
|
||||
actions = {
|
||||
["default"] = function(selected)
|
||||
for _, course in ipairs(courses) do
|
||||
if selected[1] == (course.name .. " (" .. course.short .. ")") then
|
||||
show_course_menu(course)
|
||||
break
|
||||
end
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- Function to show the fzf menu for actions on a selected course folder
|
||||
function 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
|
||||
if file:match("%.typ$") then
|
||||
table.insert(files, file)
|
||||
end
|
||||
end
|
||||
|
||||
-- Collect options
|
||||
-- TODO: implement zettel (Hausaufgaben) management
|
||||
-- For example creation of new ones and quick opening of the pdfs
|
||||
local options = {
|
||||
"Open the newest VL file",
|
||||
"Create a new VL",
|
||||
"Open the course folder",
|
||||
"Open a specific file",
|
||||
}
|
||||
|
||||
fzf.fzf_exec(options, {
|
||||
prompt = "Choose an action > ",
|
||||
actions = {
|
||||
["default"] = function(selected)
|
||||
if selected[1] == "Open the newest VL file" then
|
||||
local newest_file = get_newest_vl_file(files)
|
||||
vim.cmd("edit " .. newest_file)
|
||||
elseif selected[1] == "Create a new VL" then
|
||||
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
|
||||
fzf.fzf_exec(fn.glob(course.path .. "/*", true, true), {
|
||||
prompt = "Pick a file to open > ",
|
||||
actions = {
|
||||
["default"] = function(file)
|
||||
vim.cmd("edit " .. file[1])
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- Function to get the newest VL file based on modification time
|
||||
function get_newest_vl_file(files)
|
||||
local newest_file = nil
|
||||
local newest_time = 0
|
||||
for _, file in ipairs(files) do
|
||||
local stat = fn.getftime(file)
|
||||
if stat > newest_time then
|
||||
newest_time = stat
|
||||
newest_file = file
|
||||
end
|
||||
end
|
||||
return newest_file
|
||||
end
|
||||
|
||||
-- Function to create a new VL file based on the template and incrementing the number
|
||||
function create_new_vl(course)
|
||||
local vl_dir = course.path .. "/VL"
|
||||
local success, _ = 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
|
||||
local latest_num = 0
|
||||
for _, file in ipairs(fn.glob(vl_dir .. "/*", true, true)) do
|
||||
if file:match(course.short .. "VL(%d+).typ$") then
|
||||
local num = tonumber(file:match(course.short .. "VL(%d+).typ$"))
|
||||
if num > latest_num then
|
||||
latest_num = num
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Create new VL file with incremented number
|
||||
local new_vl_name = string.format("%sVL%d.typ", course.short, latest_num + 1)
|
||||
local new_vl_path = vl_dir .. "/" .. new_vl_name
|
||||
|
||||
-- Copy the template if it exists
|
||||
vim.fn.system({"cp", template_path, new_vl_path})
|
||||
|
||||
-- Open the new VL file
|
||||
vim.cmd("edit " .. new_vl_path)
|
||||
else
|
||||
print("Template file (template.typ) not found!")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user