Fix autocompilation of suckless software

This commit is contained in:
mintycube 2024-04-24 09:24:28 +05:00
parent ecb9b45a3d
commit 819e8661c3

View File

@ -2,50 +2,50 @@
-- [[ Highlight on yank ]]
vim.api.nvim_create_autocmd("TextYankPost", {
callback = function()
vim.highlight.on_yank({ timeout = 100 })
end,
group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }),
pattern = "*",
callback = function()
vim.highlight.on_yank({ timeout = 100 })
end,
group = vim.api.nvim_create_augroup("YankHighlight", { clear = true }),
pattern = "*",
})
-- [[ Disable Autocommenting on new lines ]]
vim.api.nvim_create_autocmd("BufEnter", {
callback = function()
vim.opt.formatoptions:remove({ "c", "r", "o" })
end,
group = vim.api.nvim_create_augroup("DisableAutocommenting", { clear = true }),
callback = function()
vim.opt.formatoptions:remove({ "c", "r", "o" })
end,
group = vim.api.nvim_create_augroup("DisableAutocommenting", { clear = true }),
})
-- [[ Update file on Focus ]]
vim.api.nvim_create_autocmd("FocusGained", {
callback = function()
vim.cmd("checktime")
end,
group = vim.api.nvim_create_augroup("UpdateOnFocus", { clear = true }),
callback = function()
vim.cmd("checktime")
end,
group = vim.api.nvim_create_augroup("UpdateOnFocus", { clear = true }),
})
-- [[ Open lf when it's a Directory ]]
vim.api.nvim_create_autocmd("VimEnter", {
callback = function(data)
local directory = vim.fn.isdirectory(data.file) == 1
if directory then
require("lf").start()
end
end,
group = vim.api.nvim_create_augroup("lf_ifDirectory", { clear = true }),
callback = function(data)
local directory = vim.fn.isdirectory(data.file) == 1
if directory then
require("lf").start()
end
end,
group = vim.api.nvim_create_augroup("lf_ifDirectory", { clear = true }),
})
-- [[ Remove trailing whitespaces ]]
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
pattern = { "*" },
callback = function()
local save_cursor = vim.fn.getpos(".")
vim.cmd([[%s/\s\+$//e]])
vim.cmd([[%s/\n\+\%$//e]])
vim.fn.setpos(".", save_cursor)
end,
group = vim.api.nvim_create_augroup("RemoveTrailingWhitespaces", { clear = true }),
pattern = { "*" },
callback = function()
local save_cursor = vim.fn.getpos(".")
vim.cmd([[%s/\s\+$//e]])
vim.cmd([[%s/\n\+\%$//e]])
vim.fn.setpos(".", save_cursor)
end,
group = vim.api.nvim_create_augroup("RemoveTrailingWhitespaces", { clear = true }),
})
-- [[ Restore last cursor position ]]
@ -54,10 +54,10 @@ vim.api.nvim_create_autocmd("BufReadPost", {
callback = function()
local line = vim.fn.line "'\""
if
line > 1
and line <= vim.fn.line "$"
and vim.bo.filetype ~= "commit"
and vim.fn.index({ "xxd", "gitrebase" }, vim.bo.filetype) == -1
line > 1
and line <= vim.fn.line "$"
and vim.bo.filetype ~= "commit"
and vim.fn.index({ "xxd", "gitrebase" }, vim.bo.filetype) == -1
then
vim.cmd 'normal! g`"zz'
end
@ -66,24 +66,27 @@ vim.api.nvim_create_autocmd("BufReadPost", {
-- [[ Reload xresources on write ]]
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = vim.fn.resolve(vim.fn.expand("~/.config/x11/xresources")),
callback = function()
-- cmd([[!xrdb % ; killall -USR1 st ; renew-dwm ; notify-send " - xresources reloaded"]])
vim.cmd([[!xrdb % ; killall -USR1 st ; renew-dwm]])
end,
group = vim.api.nvim_create_augroup("ReloadXresources", { clear = true }),
pattern = vim.fn.resolve(vim.fn.expand("~/.config/x11/xresources")),
callback = function()
-- cmd([[!xrdb % ; killall -USR1 st ; renew-dwm ; notify-send " - xresources reloaded"]])
vim.cmd([[!xrdb % ; killall -USR1 st ; renew-dwm]])
end,
group = vim.api.nvim_create_augroup("ReloadXresources", { clear = true }),
})
-- [[ Recompile suckless software on write and show notification ]]
local function recompile(path)
vim.api.nvim_create_augroup("RecompileGroup_" .. path, { clear = true })
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = vim.fn.resolve(vim.fn.expand(path)),
callback = function()
vim.cmd("!sudo make install; renew-dwm")
end,
})
vim.api.nvim_create_augroup("RecompileGroup_" .. path, { clear = true })
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
pattern = vim.fn.resolve(vim.fn.expand(path)),
callback = function()
local dir = vim.fn.fnamemodify(path, ":h")
local shell_cmd = string.format("cd %s && sudo make install && renew-dwm", dir)
vim.cmd("!" .. shell_cmd)
end,
})
end
recompile("~/.config/suckless/dwm/config.h")
recompile("~/.config/suckless/dmenu/config.h")
recompile("~/.config/suckless/st/config.h")
@ -91,17 +94,17 @@ recompile("~/.config/suckless/dwmblocks/config.h")
--[[ Close nvim if toggleterm or Outline is the last buffer ]]
vim.api.nvim_create_autocmd({ "BufEnter" }, {
pattern = "*",
callback = function()
if
vim.fn.tabpagenr("$") == 1
and vim.fn.winnr("$") == 1
and (vim.bo.ft == "toggleterm" or vim.bo.ft == "Outline")
then
vim.cmd("bd! | q")
end
end,
group = vim.api.nvim_create_augroup("CloseLast", { clear = true }),
pattern = "*",
callback = function()
if
vim.fn.tabpagenr("$") == 1
and vim.fn.winnr("$") == 1
and (vim.bo.ft == "toggleterm" or vim.bo.ft == "Outline")
then
vim.cmd("bd! | q")
end
end,
group = vim.api.nvim_create_augroup("CloseLast", { clear = true }),
})
-- [[ Autosave ]]