#!/bin/sh
 
+install_dependencies() {
+    if [[ -f /bin/dnf ]]
+    then
+        echo "installing dependencies"
+        sudo dnf install g++ libstdc++ -y
+    else
+        echo "Cannot find dnf, please install g++ and libstdc++ using your package manager"
+    fi
+}
+
 check_nvim_directory() {
        if [ -d ~/.config/nvim ]; then
                uuid=$(cat /proc/sys/kernel/random/uuid)
 elif [[ $version -eq 1 ]]; then
        version_no_lua
 fi
+install_dependencies
 
 require("nvim.lualine")
 require("nvim.toggleterm")
 require("nvim.impatient")
+require("nvim.ts-autotag")
 
 vim.cmd("highlight QuickScopePrimary guifg='#00ff00' gui=underline ctermfg=105 cterm=underline")
 vim.cmd("highlight QuickScopeSecondary guifg='#ff0000' gui=underline ctermfg=81 cterm=underline")
-
 
 tnoremap("<C-k>", "<C-\\><C-N><C-w>k")
 tnoremap("<C-l>", "<C-\\><C-N><C-w>l")
 
+nnoremap("<silent><F1>", '<Cmd>exe v:count1 . "ToggleTerm"<CR>')
+inoremap("<silent><F1>", '<Esc><Cmd>exe v:count1 . "ToggleTerm"<CR>')
+
 -- Telescope
 nnoremap(
        "<leader>f",
        "<cmd>lua require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({ previewer = false }))<CR>"
 )
 nnoremap("<C-t>", "<cmd>Telescope live_grep<CR>")
+
+-- Sane buffer delete
+nnoremap("<leader>bd", ":Bdelete<CR>")
 
 
 local function lsp_highlight_document(client)
        -- Set autocommands conditional on server_capabilities
-       if client.resolved_capabilities.document_highlight then
+       if client.server_capabilities.document_highlight then
                vim.api.nvim_exec(
                        [[
             augroup lsp_document_highlight
        )
        vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", '<cmd>lua vim.diagnostic.goto_next({ border = "rounded" })<CR>', opts)
        vim.api.nvim_buf_set_keymap(bufnr, "n", "<leader>q", "<cmd>lua vim.diagnostic.setloclist()<CR>", opts)
-       vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()' ]])
-       vim.cmd([[
+       vim.cmd([[ command! Format execute 'lua vim.lsp.buf.format()' ]])
+    vim.cmd([[
         augroup FormatOnSave
             autocmd!
             autocmd BufWritePre * :Format 
 
 M.on_attach = function(client, bufnr)
        if client.name == "tsserver" or client.name == "sumneko_lua" then
-               client.resolved_capabilities.document_formatting = false
+               client.server_capabilities.document_formatting = false
        end
        lsp_keymaps(bufnr)
        lsp_highlight_document(client)
        return
 end
 
-M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities)
+M.capabilities = cmp_nvim_lsp.default_capabilities(capabilities)
 
 return M
 
--- /dev/null
+require('ide').setup({
+})
 
        view = {
                adaptive_size = false,
                width = 30,
-               height = 30,
                hide_root_folder = false,
                side = "left",
                preserve_window_proportions = false,
 
        scrolloff = 8,
        sidescrolloff = 8,
        guifont = "monospace:h17",
+    mouse = "",
 }
 
 vim.opt.shortmess:append("c")
        augroup END
 ]])
 
-vim.cmd([[ 
-       augroup Format
-               autocmd!
-               autocmd BufWritePre *.html :normal mZgg=G`Z:delmarks Z
-       augroup END
-]])
+-- vim.cmd([[ 
+--     augroup Format
+--             autocmd!
+--             autocmd BufWritePre *.html :normal mZgg=G`Z:delmarks Z
+--     augroup END
+-- ]])
 
        -- NON LUA PLUGINS
        use("moll/vim-bbye")
 
-       use("mitsuhiko/vim-jinja")
-       --
+       --[[ use("mitsuhiko/vim-jinja") ]]
+    --[[ use("theHamsta/tree-sitter-jinja2") ]]
+    --[[ use("tpope/vim-endwise") ]]
+       
        -- Surround
        use("tpope/vim-surround")
 
     -- Fixing a bug with python indentation and treesitter
     use("Vimjas/vim-python-pep8-indent")
 
+    -- HTML Tag Completer
+    use("windwp/nvim-ts-autotag")
+
+    --[[ use("ldelossa/nvim-ide") ]]
        -- PLUGINS END --
 
        -- Automatically set up your configuration after cloning packer.nvim
 
--- /dev/null
+-- enable html parser in htmldjango file
+local import_parsers, parsers = pcall(require, 'nvim-treesitter.parsers')
+if import_parsers then
+       local parsername = parsers.filetype_to_parsername
+       parsername.htmldjango = 'html' 
+       parsername.htmljinja = 'html' 
+end
+
+
+local import_tag, autotag = pcall(require, "nvim-ts-autotag")
+if not import_tag then return end
+autotag.setup({
+       autotag = {
+               enable = true,
+       },
+       filetypes = {
+               'html', 'htmldjango',
+       },
+})