SexNvim/lua/config/cigan.lua
2025-04-10 22:48:33 +03:00

59 lines
2.4 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

vim.api.nvim_set_keymap("n", "<leader><Enter>", ":lua SaveAndRunScript()<CR>", { noremap = true, silent = true })
function SaveAndRunScript()
-- Проверяем, что открыт именно буфер ~/cigan/ui.md
local current_buf = vim.api.nvim_buf_get_name(0)
local target_file = vim.fn.expand("~/desktop/govno/ui.md")
if current_buf ~= target_file then
vim.notify("Ошибка: Открыт не файл ~/desktop/govno/ui.md", vim.log.levels.ERROR)
return
end
-- Сохраняем изменения в текущем файле
vim.cmd("write")
-- Запускаем скрипт ~/cigan/interface.py асинхронно
local script_path = vim.fn.expand("~/dev/cigan/interface.py")
vim.fn.jobstart("bash " .. script_path, {
on_exit = function(_, exit_code)
if exit_code ~= 0 then
vim.notify("Ошибка при выполнении скрипта", vim.log.levels.ERROR)
return
end
-- Обновляем буфер ~/cigan/ui.md и переходим в конец файла
vim.cmd("edit")
vim.cmd('echo "Сгенерировано!"')
--vim.cmd("normal! G") -- Переход в конец файла
-- Добавляем нажатие 20 и Ctrl+e
--vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("2<C-e>", true, false, true), "n", true)
end,
})
end
vim.api.nvim_set_keymap('n', '<leader>y', ':lua CheckBufferAndRun()<CR>', { noremap = true, silent = false })
function CheckBufferAndRun()
-- Получаем полный путь к текущему файлу
local current_file = vim.fn.expand('%:p')
-- Путь к целевому файлу
local target_file = vim.fn.expand('~/desktop/govno/ui.md')
-- Проверяем, совпадает ли текущий файл с целевым
if current_file == target_file then
-- Выполняем скрипт на удаленном сервере через SSH
vim.cmd('!ssh xer@dev "~/cigan/new_chat.sh"')
vim.cmd('echo "Новый чат создан!"')
else
-- Выводим сообщение об ошибке
vim.cmd('echo "Ошибка: Эта команда работает только в файле ~/desktop/govno/ui.md"')
end
end