From bbed1e20835f614c31b0d815e6b4377e55b8d228 Mon Sep 17 00:00:00 2001 From: venus Date: Tue, 2 Jun 2026 01:36:34 -0500 Subject: [PATCH] added functionality to easily replay last command --- lua/custom-functions.lua | 30 ++++++++++++++---------------- lua/keybinds.lua | 5 +++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lua/custom-functions.lua b/lua/custom-functions.lua index 3781f01..1c6aa61 100644 --- a/lua/custom-functions.lua +++ b/lua/custom-functions.lua @@ -2,22 +2,20 @@ -- A library file with custom functions for cleaner code elsewhere local C = {} -function C.runLastCommand() - -- TODO fix implementation - local term = require("toggleterm.terminal").get(1)-- Get terminal ID 1 - -- Save position and buffer context - if term then - local original_window = vim.api.nvim_get_current_win() - local saved_view = vim.fn.winsaveview() - -- Using \r (carriage return) or \n\n often bypasses shell interceptors - -- term:send("clear\r") - term:send("test_dev.sh\r") - vim.api.nvim_set_current_win(original_window) - vim.fn.winrestview(saved_view) - else - vim.notify("Terminal 1 is not open yet!", vim.log.levels.WARN) - end - -- Return logic +function C.RunCommand(Command) + -- TODO IMplement an autocompiler function based on context + local tt = require("toggleterm") + local command = string.lower(Command) + if command == "l" or command == "last" then tt.exec("clear && fc -e -\r") end + if command == "c" or command == "compile" then tt.exec("clear && make\r") end + vim.defer_fn(function () + vim.api.nvim_echo({ + { "▶ Terminal: ", "WarningMsg" }, + { "Running previous terminal command... ", "Normal" }, + }, true, {}) + end, 50) + return "" end + return C diff --git a/lua/keybinds.lua b/lua/keybinds.lua index 759fbdd..b61ae10 100644 --- a/lua/keybinds.lua +++ b/lua/keybinds.lua @@ -10,6 +10,7 @@ vim.cmd('silent! tmapclear') -- Clears Terminal maps -- Define your current keymaps below this line -- ========================================== vim.keymap.set('n', 'w', ':w') +package.loaded["custom-functions"] = nil local utils = require("custom-functions") -- move betwwen buffer easier @@ -25,13 +26,13 @@ vim.keymap.set('n','' ,"lua require('resize').ResizeDown()") vim.keymap.set('n','' ,'nohlsearch') vim.keymap.set('t','' ,'' ,{ desc = 'Exit terminal mode' }) vim.keymap.set('n','r' ,'TermExec cmd="clear && make"' ,{ desc = '[r]un make in terminal' }) +vim.keymap.set('n','l' ,function() utils.RunCommand("l") end ,{ desc = 'run [l]ast command in terminal' }) vim.keymap.set('n','n' ,'ToggleTerm direction=vertical name=compile size=70', { desc = 'open a [n]ew terminal' }) vim.keymap.set('n','t' ,'ToggleTerm' ,{desc = '[T]oggle all terminals'}) vim.keymap.set("n","e" ,"NvimTreeToggle" ,{desc = 'open [E]xplorer'}) --- -vim.keymap.set("n", "R" ,"source %:echo 'Config reloaded!'",{ desc = "[S]ource config file"}) -- Diagnostic keymaps vim.keymap.set('n', 'q' ,vim.diagnostic.setloclist ,{ desc = 'Open diagnostic [Q]uickfix list' }) +vim.keymap.set("n", "R" ,"source %:echo 'Config reloaded!'" ,{ desc = "[S]ource config file"}) -- Disable arrow keys in normal mode vim.keymap.set('n','' ,'echo "Use h to move!!"')