vim.api.nvim_create_augroup('HighlightYank', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
  callback = function()
    vim.highlight.on_yank { timeout = 120, on_visual = true }
  end,
  group = 'HighlightYank',
  desc = 'Highlight the yanked text',
})

vim.api.nvim_create_augroup('cursor_statusline', { clear = true })
vim.api.nvim_create_autocmd({ 'WinEnter', 'BufEnter' }, {
  callback = function()
    vim.wo.cursorline = true
  end,
  group = 'cursor_statusline',
})
vim.api.nvim_create_autocmd({ 'WinLeave', 'BufLeave' }, {
  callback = function()
    vim.wo.cursorline = false
  end,
  group = 'cursor_statusline',
})
vim.api.nvim_create_autocmd({ 'FileType' }, {
  callback = function()
    vim.wo.cursorline = false
  end,
  pattern = 'TelescopePrompt',
  group = 'cursor_statusline',
})

vim.api.nvim_create_augroup('Miscs', { clear = true })
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
  callback = function()
    vim.cmd 'silent !pkill -USR1 sxhkd'
  end,
  pattern = 'sxhkdrc',
  group = 'Miscs',
})
vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
  callback = function()
    vim.cmd 'silent !xrdb %'
  end,
  pattern = 'xresources',
  group = 'Miscs',
})
vim.api.nvim_create_autocmd('BufEnter', {
  callback = function()
    vim.cmd 'silent! lcd %:p:h'
  end,
  group = 'Miscs',
  desc = 'change the working directory',
})
vim.api.nvim_create_autocmd({ 'VimResized' }, {
  callback = function()
    vim.cmd 'tabdo wincmd ='
  end,
  group = 'Miscs',
})

vim.api.nvim_create_augroup('Terms', { clear = true })
vim.api.nvim_create_autocmd('BufEnter', {
  callback = function()
    vim.cmd 'startinsert'
  end,
  group = 'Terms',
  pattern = 'term:\\/\\/*',
})
vim.api.nvim_create_autocmd('BufLeave', {
  callback = function()
    vim.cmd 'stopinsert'
  end,
  group = 'Terms',
  pattern = 'term:\\/\\/*',
})
