added functionality to easily replay last command
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -10,6 +10,7 @@ vim.cmd('silent! tmapclear') -- Clears Terminal maps
|
||||
-- Define your current keymaps below this line
|
||||
-- ==========================================
|
||||
vim.keymap.set('n', '<leader>w', ':w<CR>')
|
||||
package.loaded["custom-functions"] = nil
|
||||
local utils = require("custom-functions")
|
||||
|
||||
-- move betwwen buffer easier
|
||||
@@ -25,13 +26,13 @@ vim.keymap.set('n','<M-Down>' ,"<cmd>lua require('resize').ResizeDown()<CR>")
|
||||
vim.keymap.set('n','<Esc>' ,'<cmd>nohlsearch<CR>')
|
||||
vim.keymap.set('t','<Esc><Esc>' ,'<C-\\><C-n>' ,{ desc = 'Exit terminal mode' })
|
||||
vim.keymap.set('n','<leader>r' ,'<cmd>TermExec cmd="clear && make"<CR>' ,{ desc = '[r]un make in terminal' })
|
||||
vim.keymap.set('n','<leader>l' ,function() utils.RunCommand("l") end ,{ desc = 'run [l]ast command in terminal' })
|
||||
vim.keymap.set('n','<leader>n' ,'<cmd>ToggleTerm direction=vertical name=compile size=70<CR>', { desc = 'open a [n]ew terminal' })
|
||||
vim.keymap.set('n','<leader>t' ,'<cmd>ToggleTerm<CR>' ,{desc = '[T]oggle all terminals'})
|
||||
vim.keymap.set("n","<leader>e" ,"<cmd>NvimTreeToggle<CR>" ,{desc = 'open [E]xplorer'})
|
||||
--
|
||||
vim.keymap.set("n", "<leader>R" ,"<cmd>source %<Cr>:echo 'Config reloaded!'<CR>",{ desc = "[S]ource config file"})
|
||||
-- Diagnostic keymaps
|
||||
vim.keymap.set('n', '<leader>q' ,vim.diagnostic.setloclist ,{ desc = 'Open diagnostic [Q]uickfix list' })
|
||||
vim.keymap.set("n", "<leader>R" ,"<cmd>source %<Cr>:echo 'Config reloaded!'<CR>" ,{ desc = "[S]ource config file"})
|
||||
|
||||
-- Disable arrow keys in normal mode
|
||||
vim.keymap.set('n','<left>' ,'<cmd>echo "Use h to move!!"<CR>')
|
||||
|
||||
Reference in New Issue
Block a user