summaryrefslogtreecommitdiff
path: root/ar/.config/TheSiahxyz/lua/thesiahxyz/utils
diff options
context:
space:
mode:
Diffstat (limited to 'ar/.config/TheSiahxyz/lua/thesiahxyz/utils')
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet.lua13
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/grid.lua105
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/init.lua116
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/icons.lua168
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua26
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/snippet.lua38
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tasks.lua227
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tmux.lua63
-rw-r--r--ar/.config/TheSiahxyz/lua/thesiahxyz/utils/utils.lua112
9 files changed, 868 insertions, 0 deletions
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet.lua
new file mode 100644
index 0000000..dd5130a
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet.lua
@@ -0,0 +1,13 @@
+local options = {
+ cheatsheet = {
+ theme = "grid", -- Options: "simple" or "grid"
+ excluded_groups = { "terminal (t)", "autopairs", "Nvim", "Opens" }, -- Exclude specific groups
+ },
+}
+
+-- Define a keymap for opening the cheatsheet
+vim.keymap.set("n", "<leader>skc", function()
+ require("thesiahxyz.utils.cheatsheet.grid")()
+end, { desc = "Open Cheatsheet" })
+
+return options
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/grid.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/grid.lua
new file mode 100644
index 0000000..6616b1e
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/grid.lua
@@ -0,0 +1,105 @@
+local api = vim.api
+local ch = require("thesiahxyz.utils.cheatsheet.init")
+local state = ch.state
+
+local ascii = {
+ " ",
+ " ",
+ "█▀▀ █░█ █▀▀ ▄▀█ ▀█▀ █▀ █░█ █▀▀ █▀▀ ▀█▀",
+ "█▄▄ █▀█ ██▄ █▀█ ░█░ ▄█ █▀█ ██▄ ██▄ ░█░",
+ " ",
+ " ",
+}
+
+return function(buf, win, action)
+ action = action or "open"
+
+ local ns = api.nvim_create_namespace("thesiah_cheatsheet")
+
+ if action == "open" then
+ state.mappings_tb = ch.organize_mappings()
+
+ buf = buf or api.nvim_create_buf(false, true)
+ win = win or api.nvim_get_current_win()
+
+ api.nvim_set_current_win(win)
+
+ -- Calculate maximum widths for lhs and rhs
+ local lhs_max_width, rhs_max_width = 0, 0
+ for _, section in pairs(state.mappings_tb) do
+ for _, mapping in ipairs(section) do
+ lhs_max_width = math.max(lhs_max_width, vim.fn.strdisplaywidth(mapping[1]))
+ rhs_max_width = math.max(rhs_max_width, vim.fn.strdisplaywidth(mapping[2]))
+ end
+ end
+
+ local total_width = lhs_max_width + rhs_max_width + 6 -- Add spacing for readability
+ local center_offset = math.floor((total_width - vim.fn.strdisplaywidth(ascii[1])) / 2)
+
+ -- Align ASCII art to the center
+ local ascii_header = vim.tbl_values(ascii)
+ for i, line in ipairs(ascii_header) do
+ ascii_header[i] = string.rep(" ", center_offset) .. line
+ end
+
+ -- Center-align the title
+ local title = "Cheatsheet"
+ local title_padding = math.floor((total_width - vim.fn.strdisplaywidth(title)) / 2)
+ local title_line = string.rep(" ", title_padding) .. title
+
+ -- Prepare buffer lines
+ local lines = {}
+ for _, line in ipairs(ascii_header) do
+ table.insert(lines, line)
+ end
+ table.insert(lines, "") -- Blank line after ASCII art
+ table.insert(lines, title_line)
+ table.insert(lines, "") -- Blank line after title
+
+ -- Add mappings grouped by section
+ for section_name, mappings in pairs(state.mappings_tb) do
+ -- Center-align the section name
+ local section_padding = math.floor((total_width - vim.fn.strdisplaywidth(section_name)) / 2)
+ table.insert(lines, string.rep(" ", section_padding) .. section_name) -- Section header
+
+ -- Add mappings aligned to lhs and rhs
+ for _, mapping in ipairs(mappings) do
+ local lhs = mapping[1]
+ local rhs = mapping[2]
+ local lhs_padding = string.rep(" ", lhs_max_width - vim.fn.strdisplaywidth(lhs))
+ local rhs_padding = string.rep(" ", rhs_max_width - vim.fn.strdisplaywidth(rhs))
+ table.insert(lines, lhs .. lhs_padding .. " " .. rhs_padding .. rhs)
+ end
+ table.insert(lines, "") -- Blank line after each section
+ end
+
+ -- Set lines into the buffer
+ api.nvim_buf_set_lines(buf, 0, -1, false, lines)
+
+ -- Highlight ASCII art and title
+ for i = 1, #ascii_header do
+ api.nvim_buf_add_highlight(buf, ns, "ThesiahAsciiHeader", i - 1, 0, -1)
+ end
+ api.nvim_buf_add_highlight(buf, ns, "Title", #ascii + 1, 0, -1)
+
+ -- Highlight section headers
+ local current_line = #ascii + 3 -- Adjust for blank lines and title
+ for section_name, mappings in pairs(state.mappings_tb) do
+ api.nvim_buf_add_highlight(buf, ns, "ThesiahSection", current_line, 0, -1)
+ current_line = current_line + #mappings + 2 -- Count section header, mappings, and blank line
+ end
+
+ -- Configure the buffer
+ vim.bo[buf].modifiable = false
+ vim.bo[buf].readonly = false
+ vim.bo[buf].buftype = ""
+ vim.bo[buf].buflisted = true
+ vim.bo[buf].filetype = "cheatsheet"
+
+ -- Set up autocmds for the cheatsheet
+ ch.autocmds(buf, win)
+
+ -- Focus on the cheatsheet buffer
+ api.nvim_set_current_buf(buf)
+ end
+end
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/init.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/init.lua
new file mode 100644
index 0000000..c4cc1f0
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/cheatsheet/init.lua
@@ -0,0 +1,116 @@
+local M = {}
+local api = vim.api
+local config = require("thesiahxyz.utils.cheatsheet") -- Load cheatsheet options
+
+local function capitalize(str)
+ return (str:gsub("^%l", string.upper))
+end
+
+M.get_mappings = function(mappings, tb_to_add)
+ local excluded_groups = config.cheatsheet.excluded_groups
+
+ for _, v in ipairs(mappings) do
+ local desc = v.desc
+
+ if not desc or (select(2, desc:gsub("%S+", "")) <= 1) or string.find(desc, "\n") then
+ goto continue
+ end
+
+ local heading = desc:match("%S+") -- Get first word
+ heading = (v.mode ~= "n" and heading .. " (" .. v.mode .. ")") or heading
+
+ if
+ vim.tbl_contains(excluded_groups, heading)
+ or vim.tbl_contains(excluded_groups, desc:match("%S+"))
+ or string.find(v.lhs, "<Plug>")
+ then
+ goto continue
+ end
+
+ heading = capitalize(heading)
+
+ if not tb_to_add[heading] then
+ tb_to_add[heading] = {}
+ end
+
+ local keybind = string.sub(v.lhs, 1, 1) == " " and "<leader> +" .. v.lhs or v.lhs
+
+ desc = v.desc:match("%s(.+)") -- Remove first word from description
+ desc = capitalize(desc)
+
+ table.insert(tb_to_add[heading], { desc, keybind })
+
+ ::continue::
+ end
+end
+
+M.organize_mappings = function()
+ local tb_to_add = {}
+ local modes = { "n", "i", "v", "t" }
+
+ for _, mode in ipairs(modes) do
+ local keymaps = api.nvim_get_keymap(mode)
+ M.get_mappings(keymaps, tb_to_add)
+
+ local bufkeymaps = api.nvim_buf_get_keymap(0, mode)
+ M.get_mappings(bufkeymaps, tb_to_add)
+ end
+
+ return tb_to_add
+end
+
+M.rand_hlgroup = function()
+ local hlgroups = {
+ "blue",
+ "red",
+ "green",
+ "yellow",
+ "orange",
+ "baby_pink",
+ "purple",
+ "white",
+ "cyan",
+ "vibrant_green",
+ "teal",
+ }
+
+ return "ThesiahHead" .. hlgroups[math.random(1, #hlgroups)]
+end
+
+M.autocmds = function(buf, win)
+ -- Set buffer options to make it searchable and navigable
+ vim.bo[buf].buflisted = true
+ vim.bo[buf].buftype = "" -- Treat it as a regular buffer
+ vim.bo[buf].swapfile = false
+ vim.bo[buf].modifiable = false -- Prevent accidental edits
+ vim.bo[buf].readonly = false -- Enable navigation and search
+ vim.bo[buf].filetype = "cheatsheet" -- Optional, to customize behavior
+
+ -- Create autocmd group for cheatsheet
+ local group_id = api.nvim_create_augroup("ThesiahCheatsheet", { clear = true })
+
+ -- Clean up when buffer is closed
+ api.nvim_create_autocmd("BufWinLeave", {
+ group = group_id,
+ buffer = buf,
+ callback = function()
+ vim.g.thesiah_cheatsheet_displayed = false
+ api.nvim_del_augroup_by_id(group_id)
+ end,
+ })
+
+ -- Keymaps for cheatsheet buffer
+ vim.keymap.set("n", "q", function()
+ api.nvim_buf_delete(buf, { force = true })
+ end, { buffer = buf })
+
+ vim.keymap.set("n", "<ESC>", function()
+ api.nvim_buf_delete(buf, { force = true })
+ end, { buffer = buf })
+end
+
+M.state = {
+ mappings_tb = {},
+}
+
+return M
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/icons.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/icons.lua
new file mode 100644
index 0000000..22d5f2d
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/icons.lua
@@ -0,0 +1,168 @@
+return {
+ diagnostics = {
+ Error = " ",
+ Hint = "󰠠 ",
+ Information = " ",
+ Question = " ",
+ Warning = " ",
+ },
+ documents = {
+ File = " ",
+ FileEmpty = " ",
+ Files = " ",
+ Folder = " ",
+ FolderEmpty = " ",
+ OpenFolder = " ",
+ OpenFolderEmpty = " ",
+ SymLink = " ",
+ SymlinkFolder = " ",
+ Import = " ",
+ },
+ git = {
+ Add = " ",
+ AddAlt = " ",
+ Branch = " ",
+ Diff = " ",
+ DiffAlt = " ",
+ Ignore = "◌ ",
+ Mod = " ",
+ Octoface = " ",
+ Remove = " ",
+ RemoveAlt = " ",
+ Rename = " ",
+ Repo = " ",
+ Tag = " ",
+ Untrack = " ",
+ },
+ kind = {
+ Class = " ",
+ Color = " ",
+ Constant = " ",
+ Constructor = "󰈏 ",
+ Copilot = " ",
+ Enum = " ",
+ EnumMember = " ",
+ Event = " ",
+ Field = " ",
+ File = " ",
+ Folder = " ",
+ Function = "󰊕 ",
+ Interface = " ",
+ Keyword = " ",
+ Language = "󱀍 ",
+ Method = " ",
+ Module = "",
+ Operator = " ",
+ Property = " ",
+ Reference = " ",
+ Snippet = " ",
+ Struct = " ",
+ Text = " ",
+ TypeParameter = " ",
+ Unit = " ",
+ Value = " ",
+ Variable = " ",
+ },
+ type = {
+ Array = " ",
+ Boolean = "⏻ ",
+ Number = " ",
+ Object = " ",
+ String = " ",
+ },
+ ui = {
+ Arrow = " ",
+ ArrowClosed = " ",
+ ArrowLeft = " ",
+ ArrowOpen = " ",
+ ArrowRight = " ",
+ Bluetooth = " ",
+ Bookmark = " ",
+ Bug = " ",
+ Calendar = " ",
+ Camera = " ",
+ Check = " ",
+ ChevronRight = "",
+ Circle = " ",
+ CircleSmall = "● ",
+ CircleSmallEmpty = "○ ",
+ Clipboard = " ",
+ Close = " ",
+ Code = " ",
+ Collection = " ",
+ Color = " ",
+ Command = " ",
+ Comment = " ",
+ Copilot = " ",
+ CopilotError = " ",
+ Corner = "└ ",
+ Dashboard = " ",
+ Database = " ",
+ Download = " ",
+ Edit = " ",
+ Edge = "│ ",
+ Electric = " ",
+ Eye = " ",
+ Fire = " ",
+ Firefox = " ",
+ Flag = " ",
+ Game = " ",
+ Gear = " ",
+ GitHub = " ",
+ Heart = " ",
+ History = " ",
+ Home = " ",
+ Incoming = " ",
+ Jump = " ",
+ Keyboard = " ",
+ Ligthbulb = "󰌵 ",
+ List = "",
+ Lock = " ",
+ Minus = "‒ ",
+ Music = "󰝚 ",
+ Neovim = " ",
+ NewFile = " ",
+ None = " ",
+ Note = " ",
+ Outgoing = " ",
+ Package = " ",
+ Paint = " ",
+ Pause = " ",
+ Pencil = " ",
+ Person = " ",
+ Pin = " ",
+ Play = " ",
+ Plug = " ",
+ Plus = " ",
+ Power = " ",
+ PowerlineArrowLeft = "",
+ PowerlineArrowRight = "",
+ PowerlineLeftRound = "",
+ PowerlineRightRound = "",
+ Project = " ",
+ Question = " ",
+ Refresh = " ",
+ Reload = " ",
+ Rocket = " ",
+ Save = "󰆓 ",
+ Search = " ",
+ Separator = "▊ ",
+ SeparatorLight = "▍",
+ SeparatorDashed = "┆",
+ SignIn = " ",
+ SignOut = " ",
+ Sleep = "󰒲 ",
+ Star = " ",
+ Table = " ",
+ Telescope = " ",
+ Terminal = " ",
+ Test = " ",
+ Time = " ",
+ Topline = "‾",
+ Trash = " ",
+ User = " ",
+ Vim = " ",
+ Wifi = " ",
+ Windows = " ",
+ },
+}
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua
new file mode 100644
index 0000000..1b1c591
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/markdown.lua
@@ -0,0 +1,26 @@
+local M = {}
+
+-- foldtext for Neovim < 0.10.0
+function M.foldtext()
+ return vim.api.nvim_buf_get_lines(0, vim.v.lnum - 1, vim.v.lnum, false)[1]
+end
+
+-- optimized treesitter foldexpr for Neovim >= 0.10.0
+function M.foldexpr()
+ local buf = vim.api.nvim_get_current_buf()
+ if vim.b[buf].ts_folds == nil then
+ -- as long as we don't have a filetype, don't bother
+ -- checking if treesitter is available (it won't)
+ if vim.bo[buf].filetype == "" then
+ return "0"
+ end
+ if vim.bo[buf].filetype:find("dashboard") then
+ vim.b[buf].ts_folds = false
+ else
+ vim.b[buf].ts_folds = pcall(vim.treesitter.get_parser, buf)
+ end
+ end
+ return vim.b[buf].ts_folds and vim.treesitter.foldexpr() or "0"
+end
+
+return M
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/snippet.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/snippet.lua
new file mode 100644
index 0000000..57bb211
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/snippet.lua
@@ -0,0 +1,38 @@
+local ls = require("luasnip")
+-- local s = ls.snippet
+local i = ls.insert_node
+local t = ls.text_node
+-- local d = ls.dynamic_node
+-- local f = ls.function_node
+local c = ls.choice_node
+-- local rep = require("luasnip.extras").rep
+-- local k = require("luasnip.nodes.key_indexer").new_key
+local r = ls.restore_node
+local fmt = require("luasnip.extras.fmt").fmt
+
+local M = {}
+M.i = 0
+
+M.js_quotes = function(index)
+ M.i = M.i + 1
+ return c(index, { fmt("'{}'", { r(1, M.i) }), fmt("`{}`", { r(1, M.i) }), fmt('"{}"', { r(1, M.i) }), t("") })
+end
+
+M.js_selector = function(index)
+ return c(index, { fmt("/{}/i", { i(1) }), fmt("'{}'", { i(1) }), fmt("`{}`", { i(1) }), t("") })
+end
+
+M.rtl_selector = function(index)
+ return c(index, { t("screen.get"), t("await screen.find"), t("screen.query") })
+end
+
+M.tracked_i_nodes = {}
+
+M.tin = function(index, key)
+ if not M.tracked_i_nodes[key] then
+ M.tracked_i_nodes[key] = i(index)
+ end
+ return M.tracked_i_nodes[key]
+end
+
+return M
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tasks.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tasks.lua
new file mode 100644
index 0000000..34d5636
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tasks.lua
@@ -0,0 +1,227 @@
+-- ~/.config/nvim/lua/user_functions/tasks.lua
+local M = {}
+
+-- Import the create_floating_scratch function from utils.lua
+local utils = require("thesiahxyz.utils.utils")
+
+function M.create_or_update_task()
+ local current_line = vim.fn.getline(".")
+ local cursor_pos = vim.fn.col(".")
+ local file_path = vim.fn.expand("%:p") -- Get full path of current file
+ local line_number = vim.fn.line(".") -- Get current line number
+
+ -- Keywords we are looking for
+ local keywords = { "TODO", "HACK", "NOTE", "PERF", "TEST", "WARN" }
+
+ for _, keyword in ipairs(keywords) do
+ local start_index, end_index = string.find(current_line, keyword)
+ if start_index then
+ local task_description = string.sub(current_line, end_index + 2, cursor_pos - 1)
+ task_description = string.gsub(task_description, "%(siah%)", "")
+ local task_tag = "+" .. string.lower(keyword)
+
+ -- Ask for project and other tags
+ local project = vim.fn.input("Enter project name: ")
+ local additional_tags_input = vim.fn.input("Enter additional tags separated by spaces: ")
+ local additional_tags = {}
+
+ -- Prefix each additional tag with a "+"
+ for tag in additional_tags_input:gmatch("%S+") do
+ table.insert(additional_tags, "+" .. tag)
+ end
+
+ -- Prepare the task command
+ local task_cmd = string.format('task add %s "%s"', task_tag, task_description)
+
+ -- Add additional tags if available
+ if #additional_tags > 0 then
+ task_cmd = task_cmd .. " " .. table.concat(additional_tags, " ")
+ end
+
+ -- Add project if available
+ if project and #project > 0 then
+ task_cmd = task_cmd .. " project:" .. project
+ end
+
+ -- Execute the task add command
+ local output = vim.fn.system(task_cmd)
+ print("Output: ", output)
+
+ for line in output:gmatch("[^\r\n]+") do
+ local task_id = string.match(line, "Created task (%d+)%.")
+ if task_id then
+ print("Task ID extracted: ", task_id)
+
+ -- Annotate task with filename and line number in the nvimline format
+ local annotation = string.format("nvimline:%s:%s", line_number, file_path)
+ local annotate_cmd = string.format('task %s annotate "%s"', task_id, annotation)
+ local annotate_output = vim.fn.system(annotate_cmd)
+
+ print("Annotation output: ", annotate_output)
+ return
+ else
+ print("Failed to extract task ID")
+ end
+ end
+ end
+ end
+end
+
+vim.api.nvim_set_keymap(
+ "i",
+ "<C-t>",
+ "<cmd>lua require('thesiahxyz.utils.tasks').create_or_update_task()<cr>",
+ { noremap = true, silent = true, desc = "Create/Update task" }
+)
+
+function M.mark_task_done()
+ -- Get the current line and parse it
+ local line = vim.api.nvim_get_current_line()
+ print("Original line: ", line)
+
+ -- Uncomment the line
+ vim.cmd("normal! gcc")
+ line = vim.api.nvim_get_current_line()
+ -- Remove (piotr1215) from the line
+ line = string.gsub(line, "%s*%(siah%)%s*", " ")
+ print("Uncommented line: ", line)
+
+ local patterns = { "TODO:", "HACK:", "NOTE:", "PERF:", "TEST:", "WARN:" }
+ local taskDescription = nil
+ for _, pattern in ipairs(patterns) do
+ local start_idx = string.find(line, pattern)
+ if start_idx then
+ taskDescription = string.sub(line, start_idx + string.len(pattern) + 1)
+ break
+ end
+ end
+ print("Task description: ", taskDescription or "nil")
+
+ -- If a task description was found, mark it as done
+ if taskDescription then
+ local output = vim.fn.system("yes | task description~'" .. taskDescription .. "' done")
+ print("Command output: ", output)
+ -- Check the command's output to make sure the task was marked done
+ if string.find(output, "Completed") then
+ -- Delete the current line
+ vim.cmd([[normal dd]])
+ end
+ end
+end
+
+vim.api.nvim_set_keymap(
+ "n",
+ "<localleader>td",
+ "<Cmd>lua require('thesiahxyz.utils.tasks').mark_task_done()<CR>",
+ { noremap = true, silent = true, desc = "Mark task done" }
+)
+
+function M.go_to_task_in_taskwarrior_tui()
+ -- Get the current line and save it as the original line
+ local original_line = vim.api.nvim_get_current_line()
+
+ -- Uncomment the line
+ vim.cmd("normal! gcc")
+ local uncommented_line = vim.api.nvim_get_current_line()
+
+ local patterns = { "TODO:", "HACK:", "NOTE:", "PERF:", "TEST:", "WARN:" }
+ local taskDescription = nil
+
+ for _, pattern in ipairs(patterns) do
+ local start_idx = string.find(uncommented_line, pattern)
+ if start_idx then
+ taskDescription = string.sub(uncommented_line, start_idx + string.len(pattern) + 1)
+ taskDescription = string.sub(taskDescription, 1, 50)
+ break
+ end
+ end
+
+ -- If a task description was found, use it to go to the task in taskwarrior-tui
+ if taskDescription then
+ -- print("Sleeping for 2 seconds before tmux switch...")
+ -- vim.cmd("sleep 2") -- sleep for 2 seconds
+ local output = vim.fn.system(" ~/.local/bin/opentasktui '" .. taskDescription .. "'")
+ end
+
+ -- Replace the line back with the original
+ vim.api.nvim_set_current_line(original_line)
+end
+
+vim.api.nvim_set_keymap(
+ "n",
+ "<localleader>tt",
+ "<Cmd>lua require('thesiahxyz.utils.tasks').go_to_task_in_taskwarrior_tui()<CR>",
+ { noremap = true, silent = true, desc = "Open taskwarrior-tui" }
+)
+
+function M.process_task_list(start_line, end_line, ...)
+ local args = { ... }
+ local modifiers = table.concat(args, " ")
+ local lines
+
+ -- If no range is provided, use the entire buffer.
+ if not start_line or not end_line then
+ start_line, end_line = 1, vim.api.nvim_buf_line_count(0)
+ end
+
+ lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
+
+ local new_lines = { "#!/bin/sh", "set -e" }
+
+ for _, line in ipairs(lines) do
+ local trimmed_line = line:gsub("^[•*%-%+]+%s*", "")
+ local links = {}
+
+ trimmed_line = trimmed_line:gsub("(https?://[%w%.%-%_/&%?=%~]+)", function(link)
+ table.insert(links, link)
+ return ""
+ end)
+
+ if #trimmed_line > 0 then
+ -- No more "\n" before "# Adding task:"; instead, just ensure it's a new entry in the table.
+ table.insert(new_lines, "") -- Ensure there's an empty line before adding a new task if desired.
+ table.insert(new_lines, "# Adding task: " .. trimmed_line)
+ table.insert(
+ new_lines,
+ "output=$(task add " .. (modifiers ~= "" and modifiers .. " " or "") .. '"' .. trimmed_line .. '")'
+ )
+ table.insert(
+ new_lines,
+ 'task_id=$(echo "$output" | grep -o "Created task [0-9]*." | cut -d " " -f 3 | tr -d ".")'
+ )
+
+ for _, link in ipairs(links) do
+ table.insert(new_lines, "task $task_id annotate -- " .. link)
+ end
+ end
+ end
+
+ -- Call the create_floating_scratch function from utils.lua
+ utils.create_floating_scratch(new_lines)
+end
+
+function M.my_custom_complete(arg_lead, cmd_line, cursor_pos)
+ -- This is your list of arguments.
+ local items = { "project:", "due:", "+next", "duration:" }
+
+ -- Filter the items based on the argument lead.
+ local matches = {}
+ for _, item in ipairs(items) do
+ if item:find(arg_lead) == 1 then
+ table.insert(matches, item)
+ end
+ end
+
+ return matches
+end
+
+vim.api.nvim_create_user_command("ProcessTaskList", function(input)
+ M.process_task_list(1, vim.api.nvim_buf_line_count(0), unpack(input.fargs))
+end, {
+ nargs = "*",
+ complete = function(arg_lead, cmd_line, cursor_pos)
+ -- Call the custom completion function
+ return M.my_custom_complete(arg_lead, cmd_line, cursor_pos)
+ end,
+})
+return M
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tmux.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tmux.lua
new file mode 100644
index 0000000..41869f8
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/tmux.lua
@@ -0,0 +1,63 @@
+local M = {}
+
+M.tmux_pane_function = function(dir)
+ -- NOTE: variable that controls the auto-cd behavior
+ local auto_cd_to_new_dir = true
+ -- NOTE: Variable to control pane direction: 'right' or 'bottom'
+ -- If you modify this, make sure to also modify TMUX_PANE_DIRECTION in the
+ -- zsh-vi-mode section on the .zshrc file
+ -- Also modify this in your tmux.conf file if you want it to work when in tmux
+ -- copy-mode
+ local pane_direction = vim.g.tmux_pane_direction or "right"
+ -- NOTE: Below, the first number is the size of the pane if split horizontally,
+ -- the 2nd number is the size of the pane if split vertically
+ local pane_size = (pane_direction == "right") and 60 or 15
+ local move_key = (pane_direction == "right") and "C-l" or ""
+ local split_cmd = (pane_direction == "right") and "-h" or "-v"
+ -- if no dir is passed, use the current file's directory
+ local file_dir = dir or vim.fn.expand("%:p:h")
+ -- Simplified this, was checking if a pane existed
+ local has_panes = vim.fn.system("tmux list-panes | wc -l"):gsub("%s+", "") ~= "1"
+ -- Check if the current pane is zoomed (maximized)
+ local is_zoomed = vim.fn.system("tmux display-message -p '#{window_zoomed_flag}'"):gsub("%s+", "") == "1"
+ -- Escape the directory path for shell
+ local escaped_dir = file_dir:gsub("'", "'\\''")
+ -- If any additional pane exists
+ if has_panes then
+ if is_zoomed then
+ -- Compare the stored pane directory with the current file directory
+ if auto_cd_to_new_dir and vim.g.tmux_pane_dir ~= escaped_dir then
+ -- If different, cd into the new dir
+ vim.fn.system("tmux send-keys -t :.+ 'cd \"" .. escaped_dir .. "\"' Enter")
+ -- Update the stored directory to the new one
+ vim.g.tmux_pane_dir = escaped_dir
+ end
+ -- If zoomed, unzoom and switch to the correct pane
+ vim.fn.system("tmux resize-pane -Z")
+ vim.fn.system("tmux send-keys " .. move_key)
+ else
+ -- If not zoomed, zoom current pane
+ vim.fn.system("tmux resize-pane -Z")
+ end
+ else
+ -- Store the initial directory in a Neovim variable
+ if vim.g.tmux_pane_dir == nil then
+ vim.g.tmux_pane_dir = escaped_dir
+ end
+ -- If no pane exists, open it with zsh and DISABLE_PULL variable
+ vim.fn.system(
+ "tmux split-window "
+ .. split_cmd
+ .. " -l "
+ .. pane_size
+ .. " 'cd \""
+ .. escaped_dir
+ .. "\" && DISABLE_PULL=1 zsh'"
+ )
+ vim.fn.system("tmux send-keys " .. move_key)
+ end
+end
+
+vim.keymap.set({ "n", "v", "i" }, "<M-\\>", M.tmux_pane_function, { desc = "Toggle terminal in tmux" })
+
+return M
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/utils.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/utils.lua
new file mode 100644
index 0000000..2925569
--- /dev/null
+++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/utils/utils.lua
@@ -0,0 +1,112 @@
+-- ~/.config/nvim/lua/thesiahxyz/utils/utils.lua
+local M = {}
+
+function M.print_current_file_dir()
+ local dir = vim.fn.expand("%:p:h")
+ if dir ~= "" then
+ print(dir)
+ end
+end
+
+function M.reload_module(name)
+ package.loaded[name] = nil
+ return require(name)
+end
+
+-- Function to reload the current Lua file
+function M.reload_current_file()
+ local current_file = vim.fn.expand("%:p")
+
+ if current_file:match("%.lua$") then
+ vim.cmd("luafile " .. current_file)
+ print("Reloaded file: " .. current_file)
+ else
+ print("Current file is not a Lua file: " .. current_file)
+ end
+end
+
+function M.insert_file_path()
+ local actions = require("telescope.actions")
+ local action_state = require("telescope.actions.state")
+
+ require("telescope.builtin").find_files({
+ cwd = "~/.config", -- Set the directory to search
+ attach_mappings = function(_, map)
+ map("i", "<CR>", function(prompt_bufnr)
+ local selected_file = action_state.get_selected_entry(prompt_bufnr).path
+ actions.close(prompt_bufnr)
+
+ -- Replace the home directory with ~
+ selected_file = selected_file:gsub(vim.fn.expand("$HOME"), "~")
+
+ -- Ask the user if they want to insert the full path or just the file name
+ local choice = vim.fn.input("Insert full path or file name? (n[ame]/p[ath]): ")
+ local text_to_insert
+ if choice == "p" then
+ text_to_insert = selected_file
+ elseif choice == "n" then
+ text_to_insert = vim.fn.fnamemodify(selected_file, ":t")
+ end
+
+ -- Move the cursor back one position
+ local col = vim.fn.col(".") - 1
+ vim.fn.cursor(vim.fn.line("."), col)
+
+ -- Insert the text at the cursor position
+ vim.api.nvim_put({ text_to_insert }, "c", true, true)
+ end)
+ return true
+ end,
+ })
+end
+
+vim.api.nvim_set_keymap(
+ "i",
+ "<M-p>",
+ "<cmd>lua require('thesiahxyz.utils.utils').insert_file_path()<cr>",
+ { noremap = true, silent = true }
+)
+function M.create_floating_scratch(content)
+ -- Get editor dimensions
+ local width = vim.api.nvim_get_option("columns")
+ local height = vim.api.nvim_get_option("lines")
+
+ -- Calculate the floating window size
+ local win_height = math.ceil(height * 0.8) + 2 -- Adding 2 for the border
+ local win_width = math.ceil(width * 0.8) + 2 -- Adding 2 for the border
+
+ -- Calculate window's starting position
+ local row = math.ceil((height - win_height) / 2)
+ local col = math.ceil((width - win_width) / 2)
+
+ -- Create a buffer and set it as a scratch buffer
+ local buf = vim.api.nvim_create_buf(false, true)
+ vim.api.nvim_buf_set_option(buf, "buftype", "nofile")
+ vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
+ vim.api.nvim_buf_set_option(buf, "filetype", "sh") -- for syntax highlighting
+
+ -- Create the floating window with a border and set some options
+ local win = vim.api.nvim_open_win(buf, true, {
+ relative = "editor",
+ row = row,
+ col = col,
+ width = win_width,
+ height = win_height,
+ border = "single", -- You can also use 'double', 'rounded', or 'solid'
+ })
+
+ -- Check if we've got content to populate the buffer with
+ if content then
+ vim.api.nvim_buf_set_lines(buf, 0, -1, true, content)
+ else
+ vim.api.nvim_buf_set_lines(buf, 0, -1, true, { "This is a scratch buffer in a floating window." })
+ end
+
+ vim.api.nvim_win_set_option(win, "wrap", false)
+ vim.api.nvim_win_set_option(win, "cursorline", true)
+
+ -- Map 'q' to close the buffer in this window
+ vim.api.nvim_buf_set_keymap(buf, "n", "q", ":q!<CR>", { noremap = true, silent = true })
+end
+
+return M