From 27c1b5b9a5cadf1d1331e4cefeaa9c8a73707b26 Mon Sep 17 00:00:00 2001 From: talha Date: Sun, 19 Nov 2023 15:05:03 +0500 Subject: Added harpoon --- lua/talha/functions.lua | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 lua/talha/functions.lua (limited to 'lua/talha/functions.lua') diff --git a/lua/talha/functions.lua b/lua/talha/functions.lua new file mode 100644 index 0000000..946bfd8 --- /dev/null +++ b/lua/talha/functions.lua @@ -0,0 +1,62 @@ +local Path = require"plenary.path" + +function CreateDailyNote() + local file_path = vim.api.nvim_buf_get_name(0) + local dir_path = file_path + local path_obj = Path:new(file_path) + + if path_obj:is_file() == true then + path_obj = path_obj:parent() -- get the parent directory + dir_path = path_obj:_fs_filename() + end + + local today_date_fmt = os.date('%Y-%m-%d') + local daily_note_file_name = today_date_fmt .. '.md' + local daily_note_file_obj = path_obj:joinpath(daily_note_file_name) + + local template_file_name = '.daily-notes-template.md' + local template_file_obj = path_obj:joinpath(template_file_name) + + local status = template_file_obj:copy({destination=daily_note_file_obj}) + + -- check if operation was a success + if status[daily_note_file_obj] == false then + print('Error! failed to create daily note') + print([[Possible Causes: + 1. No `.daily-notes-template.md` found + 2. Something went wrong with copy, in which case check nvim config]]) + return + end + + vim.cmd('e ' .. daily_note_file_obj:_fs_filename()) +end + +local function _ReloadConfigsInPath(path_selector) + local config_paths = vim.fn.glob(path_selector, true, true) + + for _, filepath in ipairs(config_paths) do + dofile(filepath) + end +end + +function ReloadLuaConfig() + for name,_ in pairs(package.loaded) do + if name:match('^linux') then + package.loaded[name] = nil + end + end + + -- Reload init/ directory + local lua_path_selector = vim.fn.stdpath('config') .. '/lua/**/*.lua' + _ReloadConfigsInPath(lua_path_selector) + + -- local after_path_selector = vim.fn.stdpath('config') .. '/after/**/*.lua' + _ReloadConfigsInPath(after_path_selector) + + print('Nvim configurations reloaded') +end + +function ToggleSpellCheck() + vim.opt.spell = not(vim.opt.spell:get()) + vim.opt.spelllang = 'en_us' +end -- cgit v1.2.3