diff --git a/init.lua b/init.lua index 4b56726..19e0153 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,8 @@ require("pika.core") require("pika.lazy") +vim.api.nvim_create_user_command("Snippets", function() + require("telesnip").snippet_picker() +end, {}) -- ─< Call the function to set the desired colorscheme >──────────────────────────────── -- ╭──────────────────────────────────────────────────────╮ diff --git a/lua/pika/core/keymaps.lua b/lua/pika/core/keymaps.lua index c1f3524..710ef62 100644 --- a/lua/pika/core/keymaps.lua +++ b/lua/pika/core/keymaps.lua @@ -17,6 +17,7 @@ map("v", "", "gc", { desc = "comment toggle", remap = true }) -- ─< cmd line >──────────────────────────────────────────────────────────────────────── vim.api.nvim_set_keymap("n", ":", "FineCmdline", { noremap = true }) +map("n", "T", "FineCmdline") -- ─< Terminal >──────────────────────────────────────────────────────────────────────── map("t", "", "", { desc = "terminal escape terminal mode" }) diff --git a/lua/pika/plugins/colorschemes.lua b/lua/pika/plugins/colorschemes.lua index 089f0df..d24f68f 100644 --- a/lua/pika/plugins/colorschemes.lua +++ b/lua/pika/plugins/colorschemes.lua @@ -1,46 +1,37 @@ return { - { "folke/tokyonight.nvim" }, - { "luisiacc/gruvbox-baby" }, - { "zootedb0t/citruszest.nvim" }, - -- { "catppuccin/nvim", name = "catppuccin" }, - -- { "rose-pine/neovim" }, - { "jacoborus/tender.vim" }, - { "sontungexpt/witch" }, - { 'AlexvZyl/nordic.nvim' }, - { "eldritch-theme/eldritch.nvim" }, - { 'kartikp10/noctis.nvim' }, - { 'shrikecode/kyotonight.vim' }, - { - 'uloco/bluloco.nvim', - lazy = false, - dependencies = { 'rktjmp/lush.nvim' }, - config = function() - -- your optional config goes here, see below. - end, - }, - { - "ribru17/bamboo.nvim", - lazy = false, - -- priority = 1000, -- Make sure to load this before all the other start plugins. - config = function() - require("bamboo").setup({ - -- ────────────────────────────< optional configuration here >───────────────────────── - code_style = { - comments = { italic = false, bold = true }, - conditionals = { italic = true }, - keywords = { bold = true }, - functions = {}, - namespaces = { italic = true }, - parameters = { italic = true }, - strings = {}, - variables = { bold = true }, - }, - -- ─< Custom Highlights -- >──────────────────────────────────────────────────────────── - colors = {}, -- Override default colors - highlights = { -- Override highlight groups - ["@comment"] = { fg = "#555653" }, - }, - }) - end, - }, + { "folke/tokyonight.nvim" }, + { "luisiacc/gruvbox-baby" }, + { "zootedb0t/citruszest.nvim" }, + -- { "catppuccin/nvim", name = "catppuccin" }, + -- { "rose-pine/neovim" , name = "rose-pine" }, + { "jacoborus/tender.vim" }, + { "sontungexpt/witch" }, + { "AlexvZyl/nordic.nvim" }, + { "eldritch-theme/eldritch.nvim" }, + { "kartikp10/noctis.nvim" }, + { "shrikecode/kyotonight.vim" }, + { "uloco/bluloco.nvim", dependencies = { "rktjmp/lush.nvim" } }, + { + "ribru17/bamboo.nvim", + config = function() + require("bamboo").setup({ + -- ────────────────────────────< optional configuration here >───────────────────────── + code_style = { + comments = { italic = false, bold = true }, + conditionals = { italic = true }, + keywords = { bold = true }, + functions = {}, + namespaces = { italic = true }, + parameters = { italic = true }, + strings = {}, + variables = { bold = true }, + }, + -- ─< Custom Highlights -- >──────────────────────────────────────────────────────────── + colors = {}, -- Override default colors + highlights = { -- Override highlight groups + ["@comment"] = { fg = "#555653" }, + }, + }) + end, + }, } diff --git a/lua/pika/plugins/init.lua b/lua/pika/plugins/init.lua index c5d378d..b006208 100644 --- a/lua/pika/plugins/init.lua +++ b/lua/pika/plugins/init.lua @@ -2,5 +2,5 @@ return { "nvim-lua/plenary.nvim", -- lua functions that many plugins use "christoomey/vim-tmux-navigator", -- tmux & split window navigation "dstein64/nvim-scrollview", - { 'echasnovski/mini.surround', version = false }, + "folke/lsp-colors.nvim", } diff --git a/lua/pika/plugins/mini-pairs.lua.disabled b/lua/pika/plugins/mini-pairs.lua.disabled index b95e892..c98e7a7 100644 --- a/lua/pika/plugins/mini-pairs.lua.disabled +++ b/lua/pika/plugins/mini-pairs.lua.disabled @@ -1,20 +1,21 @@ -return{ - "echasnovski/mini.pairs", - name = "mini-pairs", - event = "VeryLazy", - opts = { - modes = { insert = true, command = true, terminal = false }, - -- skip autopair when next character is one of these - skip_next = [=[[%w%%%'%[%"%.%`%$]]=], - -- skip autopair when the cursor is inside these treesitter nodes - skip_ts = { "string" }, - -- skip autopair when next character is closing pair - -- and there are more closing pairs than opening pairs - skip_unbalanced = true, - -- better deal with markdown code blocks - markdown = true, - }, - config = function() - require("mini-pairs") - end, +return { + "echasnovski/mini.pairs", + name = "mini-pairs", + lazy = false, + event = "VeryLazy", + opts = { + modes = { insert = true, command = true, terminal = false }, + -- skip autopair when next character is one of these + skip_next = [=[[%w%%%'%[%"%.%`%$]]=], + -- skip autopair when the cursor is inside these treesitter nodes + skip_ts = { "string" }, + -- skip autopair when next character is closing pair + -- and there are more closing pairs than opening pairs + skip_unbalanced = true, + -- better deal with markdown code blocks + markdown = true, + }, + config = function() + require("mini-pairs") + end, } diff --git a/lua/pika/plugins/neo-tree.lua b/lua/pika/plugins/neo-tree.lua index 5d6c49e..9fca28f 100644 --- a/lua/pika/plugins/neo-tree.lua +++ b/lua/pika/plugins/neo-tree.lua @@ -1,101 +1,115 @@ local function setup_open_file_indicators() - -- Table to store open buffers - local open_buffers = {} + -- Table to store open buffers + local open_buffers = {} - -- Function to update open_buffers table - local function update_open_buffers() - open_buffers = {} - for _, buf in ipairs(vim.api.nvim_list_bufs()) do - if vim.api.nvim_buf_is_valid(buf) and vim.bo[buf].buflisted then - local file_path = vim.api.nvim_buf_get_name(buf) - open_buffers[file_path] = true - end - end - end + -- Function to update open_buffers table + local function update_open_buffers() + open_buffers = {} + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_is_valid(buf) and vim.bo[buf].buflisted then + local file_path = vim.api.nvim_buf_get_name(buf) + open_buffers[file_path] = true + end + end + end - -- Update open_buffers initially - update_open_buffers() + -- Update open_buffers initially + update_open_buffers() - -- Set up autocmds to update open_buffers and refresh Neo-tree - local group = vim.api.nvim_create_augroup("NeoTreeOpenFileIndicator", { clear = true }) - vim.api.nvim_create_autocmd({"BufAdd", "BufDelete", "BufWipeout"}, { - group = group, - callback = function() - update_open_buffers() - if package.loaded["neo-tree.sources.manager"] then - require("neo-tree.sources.manager").refresh("filesystem") - end - end, - }) + -- Set up autocmds to update open_buffers and refresh Neo-tree + local group = vim.api.nvim_create_augroup("NeoTreeOpenFileIndicator", { clear = true }) + vim.api.nvim_create_autocmd({ "BufAdd", "BufDelete", "BufWipeout" }, { + group = group, + callback = function() + update_open_buffers() + if package.loaded["neo-tree.sources.manager"] then + require("neo-tree.sources.manager").refresh("filesystem") + end + end, + }) - -- Custom component to display open file indicator - local function open_file_indicator(config, node, state) - local result = require("neo-tree.sources.common.components").icon(config, node, state) - if node.type == "file" and open_buffers[node:get_id()] then - result.text = result.text .. "󱞇 " - end - return result - end + -- Custom component to display open file indicator + local function open_file_indicator(config, node, state) + local result = require("neo-tree.sources.common.components").icon(config, node, state) + if node.type == "file" and open_buffers[node:get_id()] then + result.text = result.text .. "󱞇 " + end + return result + end - return open_file_indicator + return open_file_indicator end return { - { - "nvim-neo-tree/neo-tree.nvim", - opts = function() - return { - sources = { "filesystem", "buffers", "git_status" }, - open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" }, - close_if_last_window = true, - popup_border_style = "rounded", - enable_git_status = true, - enable_diagnostics = true, - filesystem = { - bind_to_cwd = false, - follow_current_file = { enabled = true }, - use_libuv_file_watcher = true, - components = { - icon = setup_open_file_indicators(), - }, - }, - window = { - mappings = { - ["l"] = "open", - ["o"] = "open", - ["C-v"] = "open_split", - ["h"] = "close_node", - [""] = "none", - ["O"] = { - function(state) - require("lazy.util").open(state.tree:get_node().path, { system = true }) - end, - desc = "Open with System Application", - }, - ["P"] = { "toggle_preview", config = { use_float = true } }, - }, - }, - default_component_configs = { - indent = { - with_expanders = true, - expander_collapsed = "", - expander_expanded = "", - expander_highlight = "NeoTreeExpander", - }, - git_status = { - symbols = { - unstaged = "󰄱", - staged = "󰱒", - }, - }, - } - } - end, - branch = "v3.x", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-tree/nvim-web-devicons", - "3rd/image.nvim", - }, - } + { + "nvim-neo-tree/neo-tree.nvim", + opts = function() + -- Set the keymap when the Neo-tree buffer is opened + vim.api.nvim_create_autocmd("FileType", { + pattern = "neo-tree", + callback = function() + vim.api.nvim_buf_set_keymap( + 0, + "n", + "cd", + "FineCmdline Neotree dir=", + { noremap = true, silent = true } + ) + end, + }) + return { + sources = { "filesystem", "buffers", "git_status" }, + open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" }, + close_if_last_window = false, + popup_border_style = "rounded", + use_float = true, + enable_git_status = true, + enable_diagnostics = true, + filesystem = { + bind_to_cwd = false, + follow_current_file = { enabled = true }, + use_libuv_file_watcher = true, + components = { + icon = setup_open_file_indicators(), + }, + }, + window = { + mappings = { + ["l"] = "open", + ["o"] = "open", + ["C-v"] = "open_split", + ["h"] = "close_node", + [""] = "none", + ["O"] = { + function(state) + require("lazy.util").open(state.tree:get_node().path, { system = true }) + end, + desc = "Open with System Application", + }, + ["P"] = { "toggle_preview", config = { use_float = true } }, + }, + }, + default_component_configs = { + indent = { + with_expanders = true, + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", + }, + git_status = { + symbols = { + unstaged = "󰄱", + staged = "󰱒", + }, + }, + }, + } + end, + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", + "3rd/image.nvim", + }, + }, } diff --git a/lua/pika/plugins/telekasten.lua b/lua/pika/plugins/telekasten.lua deleted file mode 100644 index f56aea1..0000000 --- a/lua/pika/plugins/telekasten.lua +++ /dev/null @@ -1,6 +0,0 @@ -return{ - { - 'renerocksai/telekasten.nvim', - dependencies = {'nvim-telescope/telescope.nvim'} - }, -} diff --git a/lua/telesnip/init.lua b/lua/telesnip/init.lua new file mode 100644 index 0000000..56a5400 --- /dev/null +++ b/lua/telesnip/init.lua @@ -0,0 +1,78 @@ +local M = {} + +local function get_snippets() + local snippets = {} + local base_path = vim.fn.stdpath("config") .. "/lua/telesnip/snippets/" + local languages = { "bash", "lua", "fish" } -- Extend this as needed + + for _, lang in ipairs(languages) do + local path = base_path .. lang + local files = vim.fn.glob(path .. "/*", false, true) + for _, file in ipairs(files) do + local snippet_name = vim.fn.fnamemodify(file, ":t") + table.insert(snippets, { + name = snippet_name, + path = file, + language = lang, + }) + end + end + + return snippets +end + +M.snippet_picker = function() + local snippets = get_snippets() + + local opts = require("telescope.themes").get_dropdown({}) + require("telescope.pickers") + .new(opts, { + prompt_title = "Snippets", + finder = require("telescope.finders").new_table({ + results = snippets, + entry_maker = function(entry) + return { + value = entry, + display = entry.name, + ordinal = entry.name, + path = entry.path, + } + end, + }), + sorter = require("telescope.config").values.generic_sorter(opts), + previewer = require("telescope.previewers").new_buffer_previewer({ + define_preview = function(self, entry) + -- Read the snippet file content + local lines = vim.fn.readfile(entry.path) + + -- Set the buffer's lines + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines) + + -- Get file extension for syntax highlighting + local ext = vim.fn.fnamemodify(entry.path, ":e") + vim.api.nvim_buf_set_option(self.state.bufnr, "filetype", ext) + end, + }), + attach_mappings = function(_, map) + map("i", "", function(prompt_bufnr) + local selection = require("telescope.actions.state").get_selected_entry() + local snippet_content = vim.fn.readfile(selection.path) + local current_buf = vim.api.nvim_get_current_buf() + local row, _ = unpack(vim.api.nvim_win_get_cursor(0)) + + -- Insert snippet content at the current line + vim.api.nvim_buf_set_lines(current_buf, row - 1, row - 1, false, snippet_content) + + -- Check if the user is in normal mode, and switch to insert mode + if vim.fn.mode() == "n" then + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("i", true, false, true), "n", true) + end + require("telescope.actions").close(prompt_bufnr) + end) + return true + end, + }) + :find() +end + +return M diff --git a/lua/telesnip/snippets/bash/check_root.sh b/lua/telesnip/snippets/bash/check_root.sh new file mode 100644 index 0000000..7710618 --- /dev/null +++ b/lua/telesnip/snippets/bash/check_root.sh @@ -0,0 +1,15 @@ +# Check if the user is root and set sudo variable if necessary +check_root() { + if [[ "${EUID}" -ne 0 ]]; then + if command_exists sudo; then + echo_binfo "User is not root. Using sudo for privileged operations." + _sudo="sudo" + else + echo_error "No sudo found and you're not root! Can't install packages." + return 1 + fi + else + echo_binfo "Root access confirmed." + _sudo="" + fi +}