added functionality to easily replay last command

This commit is contained in:
venus
2026-06-02 01:36:34 -05:00
parent 07940444c9
commit bbed1e2083
2 changed files with 17 additions and 18 deletions

View File

@@ -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