From 88a59af55b1bb0074e8982d97f532a9945fa0166 Mon Sep 17 00:00:00 2001 From: "asep.komarudin" Date: Mon, 20 May 2024 06:21:21 +0700 Subject: [PATCH] add: update config --- lazy-lock.json | 2 +- lua/user/utils.lua | 87 ++++++++++++++++++++++++++++++ lua/user/whichkey.lua | 119 +++++------------------------------------- 3 files changed, 102 insertions(+), 106 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index 943bc74..7bdd4c6 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -28,7 +28,7 @@ "none-ls-extras.nvim": { "branch": "main", "commit": "336e84b9e43c0effb735b08798ffac382920053b" }, "none-ls.nvim": { "branch": "main", "commit": "37671797d6e5f9bd0ee3ab965ab2e6de251e1930" }, "nui.nvim": { "branch": "main", "commit": "a0fd35fcbb4cb479366f1dc5f20145fd718a3733" }, - "nvim-autopairs": { "branch": "master", "commit": "b0b79e42a28f09719a7da9534c3731fa37319d9b" }, + "nvim-autopairs": { "branch": "master", "commit": "c15de7e7981f1111642e7e53799e1211d4606cb9" }, "nvim-cmp": { "branch": "main", "commit": "5260e5e8ecadaf13e6b82cf867a909f54e15fd07" }, "nvim-colorizer.lua": { "branch": "master", "commit": "85855b38011114929f4058efc97af1059ab3e41d" }, "nvim-lspconfig": { "branch": "master", "commit": "cf3dd4a290084a868fac0e2e876039321d57111c" }, diff --git a/lua/user/utils.lua b/lua/user/utils.lua index 5953b1b..809caf3 100644 --- a/lua/user/utils.lua +++ b/lua/user/utils.lua @@ -41,4 +41,91 @@ function M.bufremove(buf) end end +function M._LAZYGIT_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local lazygit = Terminal:new({ cmd = "lazygit", hidden = true }) + lazygit:toggle() +end + +function M._NODE_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local node = Terminal:new({ cmd = "node", hidden = true }) + node:toggle() +end + +function M._BTOP_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local htop = Terminal:new({ cmd = "btop", hidden = true }) + htop:toggle() +end + +function M._PYTHON_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local python = Terminal:new({ cmd = "python", hidden = true }) + python:toggle() +end + +function M._NEWTAB_TOGGLE() + local Terminal = require("toggleterm.terminal").Terminal + local pwsh = Terminal:new({ cmd = "pwsh", hidden = true, direction = "tab" }) + pwsh:toggle() +end + +function M._OPEN_EXPLORER() + local Terminal = require("toggleterm.terminal").Terminal + local pwsh = Terminal:new({ cmd = "explorer .", hidden = true, direction = "tab" }) + pwsh:toggle() +end + +function M._LIVE_SERVER() + local Terminal = require("toggleterm.terminal").Terminal + local live_server = Terminal:new({ + cmd = "live-server", + hidden = true, + direction = "tab", + }) + live_server:toggle() +end + +function M._OPEN_ALACRITTY() + -- open alacritty new windows current directory + vim.cmd("silent !alacritty --working-directory " .. vim.fn.getcwd()) +end + +function M._OPEN_WEZTERM() + -- open wezterm new windows current directory + vim.cmd("silent !wezterm start --cwd " .. vim.fn.getcwd()) +end + +-- get folder name from current directory +function M._get_folder_name() + return vim.fn.fnamemodify(vim.fn.getcwd(), ":t") +end + +function M._OPEN_WEZTERM_TAB() + -- open new tab wezterm current directory + vim.cmd('silent !wezterm cli spawn --cwd "' .. vim.fn.getcwd() .. '"') +end + +function M._SET_TAB_TITLE() + -- set tab title + vim.cmd('silent !wezterm cli set-tab-title "' .. _get_folder_name() .. '"') +end + +function M._CLOSE_BUFFER() + local buf = vim.api.nvim_get_current_buf() + -- delete current buffer + require("bufdelete").bufdelete(buf, true) +end + +-- function for close all bufferline +function M._CLOSE_ALL_BUFFER() + -- get all buffer + local bufs = vim.api.nvim_list_bufs() + -- loop through all buffer + for _, buf in pairs(bufs) do + require("user.utils").bufdelete(buf) + end +end + return M diff --git a/lua/user/whichkey.lua b/lua/user/whichkey.lua index e983677..6be11a8 100644 --- a/lua/user/whichkey.lua +++ b/lua/user/whichkey.lua @@ -5,103 +5,9 @@ end -- config for toggleterm -function _LAZYGIT_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local lazygit = Terminal:new({ cmd = "lazygit", hidden = true }) - lazygit:toggle() -end - -function _NODE_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local node = Terminal:new({ cmd = "node", hidden = true }) - node:toggle() -end - -function _HTOP_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local htop = Terminal:new({ cmd = "htop", hidden = true }) - htop:toggle() -end - -function _BTOP_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local htop = Terminal:new({ cmd = "btop", hidden = true }) - htop:toggle() -end - -function _BTM_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local htop = Terminal:new({ cmd = "btm", hidden = true }) - htop:toggle() -end - -function _PYTHON_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local python = Terminal:new({ cmd = "python", hidden = true }) - python:toggle() -end - -function _NEWTAB_TOGGLE() - local Terminal = require("toggleterm.terminal").Terminal - local pwsh = Terminal:new({ cmd = "pwsh", hidden = true, direction = "tab" }) - pwsh:toggle() -end - -function _OPEN_EXPLORER() - local Terminal = require("toggleterm.terminal").Terminal - local pwsh = Terminal:new({ cmd = "explorer .", hidden = true, direction = "tab" }) - pwsh:toggle() -end - -function _LIVE_SERVER() - local Terminal = require("toggleterm.terminal").Terminal - local live_server = Terminal:new({ - cmd = "live-server", - hidden = true, - direction = "tab", - }) - live_server:toggle() -end - -function _OPEN_ALACRITTY() - -- open alacritty new windows current directory - vim.cmd("silent !alacritty --working-directory " .. vim.fn.getcwd()) -end - -function _OPEN_WEZTERM() - -- open wezterm new windows current directory - vim.cmd("silent !wezterm start --cwd " .. vim.fn.getcwd()) -end - --- get folder name from current directory -local _get_folder_name = function() - return vim.fn.fnamemodify(vim.fn.getcwd(), ":t") -end - -function _OPEN_WEZTERM_TAB() - -- open new tab wezterm current directory - vim.cmd('silent !wezterm cli spawn --cwd "' .. vim.fn.getcwd() .. '"') -end - function _SET_TAB_TITLE() -- set tab title - vim.cmd('silent !wezterm cli set-tab-title "' .. _get_folder_name() .. '"') -end - -function _CLOSE_BUFFER() - local buf = vim.api.nvim_get_current_buf() - -- delete current buffer - require("bufdelete").bufdelete(buf, true) -end - --- function for close all bufferline -function _CLOSE_ALL_BUFFER() - -- get all buffer - local bufs = vim.api.nvim_list_bufs() - -- loop through all buffer - for _, buf in pairs(bufs) do - require("bufdelete").bufdelete(buf, true) - end + vim.cmd('silent !wezterm cli set-tab-title "' .. require("user.utils")._get_folder_name() .. '"') end local icons = require("user.icons") @@ -227,7 +133,10 @@ local mappings = { ["w"] = { "w!", "󰆓 Save" }, ["q"] = { "q!", "󰿅 Quit" }, -- open exloler and close toggleterm - ["o"] = { "lua _OPEN_EXPLORER()lua require('toggleterm').toggle()", "󱏒 Open Explorer" }, + ["o"] = { + "lua require('user.utils')._OPEN_EXPLORER()", + "󱏒 Open Explorer", + }, ["h"] = { "nohlsearch", "󱪿 No Highlight" }, ["f"] = { "Telescope find_files ", @@ -248,7 +157,7 @@ local mappings = { "All Buffer", }, -- close current active buffer - c = { "lua _CLOSE_BUFFER()", "Close current buffer" }, + c = { "lua require('user.utils').bufremove()", "Close current buffer" }, -- bufferline close left d = { "BufferLineCloseLeft", @@ -273,7 +182,7 @@ local mappings = { g = { name = "  Git", - g = { "lua _LAZYGIT_TOGGLE()", "Lazygit" }, + g = { "lua require('user.utils')._LAZYGIT_TOGGLE()", "Lazygit" }, j = { "lua require 'gitsigns'.next_hunk()", "Next Hunk" }, k = { "lua require 'gitsigns'.prev_hunk()", "Prev Hunk" }, l = { "lua require 'gitsigns'.blame_line()", "Blame" }, @@ -340,18 +249,18 @@ local mappings = { t = { name = "  Terminal", l = { "terminal live-server", "Live Server" }, - P = { "lua _NEWTAB_TOGGLE()", "Power Shell" }, + P = { "lua require('user.utils')._NEWTAB_TOGGLE()", "Power Shell" }, x = { "ToggleTermToggleAll!", "Close Tab" }, - n = { "lua _NODE_TOGGLE()", "Node" }, - b = { "lua _BTOP_TOGGLE()", "Btop" }, - p = { "lua _PYTHON_TOGGLE()", "Python" }, + n = { "lua require('user.utils')._NODE_TOGGLE()", "Node" }, + b = { "lua require('user.utils')._BTOP_TOGGLE()", "Btop" }, + p = { "lua require('user.utils')._PYTHON_TOGGLE()", "Python" }, f = { "ToggleTerm direction=float", "Float" }, h = { "ToggleTerm size=10 direction=horizontal", "Horizontal" }, v = { "ToggleTerm size=80 direction=vertical", "Vertical" }, s = { "ToggleTerm direction=tab", "New Tab" }, - a = { "lua _OPEN_ALACRITTY()", "Open Alacritty" }, - w = { "lua _OPEN_WEZTERM()", "Open Wezterm" }, - t = { "lua _OPEN_WEZTERM_TAB()", "Open Tab Wezterm" }, + a = { "lua require('user.utils')._OPEN_ALACRITTY()", "Open Alacritty" }, + w = { "lua require('user.utils')._OPEN_WEZTERM()", "Open Wezterm" }, + t = { "lua require('user.utils')._OPEN_WEZTERM_TAB()", "Open Tab Wezterm" }, j = { "lua _SET_TAB_TITLE()", "Set Tab Title" }, }, r = {