local function H(H)vim.cmd(H..(" \116\101\114\109\058\047\047"..(vim.g.global_shell or vim.env.SHELL or vim.o.shell)))end local function A()vim.keymap.set("\116","\060\067-\104\062","\060\099-\092\062\060\099-\110\062\060\099-\119\062\104")vim.keymap.set("\116","\060\067-\106\062","\060\099-\092\062\060\099-\110\062\060\099-\119\062\106")vim.keymap.set("\116","\060\067-\107\062","\060\099-\092\062\060\099-\110\062\060\099-\119\062\107")vim.keymap.set("\116","\060\067-\108\062","\060\099-\092\062\060\099-\110\062\060\099-\119\062\108")vim.keymap.set("\116","\060\065-\105\062","\060\099-\092\062\060\099-\110\062")vim.keymap.set("\116","\074\074","\060\099-\092\062\060\099-\110\062")vim.keymap.set("\110","\060\108\101\097\100\101\114\062\093\111",function()H("\101\100\105\116")end)vim.keymap.set("\110","\060\108\101\097\100\101\114\062\093\091",function()H("\115\112\108\105\116")end)vim.keymap.set("\110","\060\108\101\097\100\101\114\062\093\093",function()H("\118\115\112\108\105\116")end)vim.keymap.set("\110","\060\108\101\097\100\101\114\062\093\112",function()H("\116\097\098\101\100\105\116")end)end local function K()local H=vim.api.nvim_create_augroup("\057\095\084\101\114\109\105\110\097\108",{})vim.api.nvim_create_autocmd("\084\101\114\109\079\112\101\110",{group=H;callback=function()vim.wo.number=false vim.cmd("\115\116\097\114\116\105\110\115\101\114\116\033")end})vim.api.nvim_create_autocmd("\087\105\110\069\110\116\101\114",{group=H;callback=function()if vim.bo.buftype=="\116\101\114\109\105\110\097\108"then vim.cmd("\115\116\097\114\116\105\110\115\101\114\116\033")end end})vim.api.nvim_create_autocmd("\084\101\114\109\069\110\116\101\114",{group=H;callback=function()vim.wo.number=false end})vim.api.nvim_create_autocmd("\084\101\114\109\067\108\111\115\101",{group=H,callback=function()vim.fn.feedkeys("\060\101\115\099\062")end})end local function e()A()K()end e()
-- custom terminal wrapper

local function open_terminal(how)
  vim.cmd(
    how .. " term://" .. (vim.g.global_shell or vim.env.SHELL or vim.o.shell)
  )
end

local function setup_keymappings()
  -- move between windows
  vim.keymap.set("t", "<C-h>", "<c-\\><c-n><c-w>h")
  vim.keymap.set("t", "<C-j>", "<c-\\><c-n><c-w>j")
  vim.keymap.set("t", "<C-k>", "<c-\\><c-n><c-w>k")
  vim.keymap.set("t", "<C-l>", "<c-\\><c-n><c-w>l")

  -- exit normal mode
  vim.keymap.set("t", "<A-i>", "<c-\\><c-n>")
  vim.keymap.set("t", "JJ", "<c-\\><c-n>")

  -- run terminal mappings
  vim.keymap.set("n", "<leader>]o", function()
    open_terminal("edit")
  end)

  vim.keymap.set("n", "<leader>][", function()
    open_terminal("split")
  end)

  vim.keymap.set("n", "<leader>]]", function()
    open_terminal("vsplit")
  end)

  vim.keymap.set("n", "<leader>]p", function()
    open_terminal("tabedit")
  end)
end

local function setup_autogroup()
  local group = vim.api.nvim_create_augroup("9_Terminal", {})

  vim.api.nvim_create_autocmd("TermOpen", {
    group = group,
    callback = function()
      vim.wo.number = false
      vim.cmd("startinsert!")
    end,
  })

  vim.api.nvim_create_autocmd("WinEnter", {
    group = group,
    callback = function()
      if vim.bo.buftype == "terminal" then
        vim.cmd("startinsert!")
      end
    end,
  })

  vim.api.nvim_create_autocmd("TermEnter", {
    group = group,
    callback = function()
      vim.wo.number = false
    end,
  })

  vim.api.nvim_create_autocmd("TermClose", {
    group = group,
    callback = function()
      vim.fn.feedkeys("<esc>")
    end,
  })
end

local function setup()
  setup_keymappings()
  setup_autogroup()
end

setup()
