aboutsummaryrefslogtreecommitdiff
path: root/dot_config/fish/config.fish.tmpl
blob: 284e9dd86515c3bc37ede3592ead2f3dbeaccd61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# source /usr/share/cachyos-fish-config/cachyos-config.fish

function fish_greeting
  {{- if eq .chezmoi.hostname "ubuntu" }}
    if test -z "$TMUX"
        tmux new -As default
    end
  {{- else }}
   fastfetch
  {{- end }}
end

# Add ~/.local/bin to PATH
if test -d ~/.local/bin
    if not contains -- ~/.local/bin $PATH
        set -p PATH ~/.local/bin
    end
end

# Add depot_tools to PATH
if test -d ~/Applications/depot_tools
    if not contains -- ~/Applications/depot_tools $PATH
        set -p PATH ~/Applications/depot_tools
    end
end

# Fish command history
function history
    builtin history --show-time='%F %T '
end

# Copy DIR1 DIR2
function copy
    set count (count $argv | tr -d \n)
    if test "$count" = 2; and test -d "$argv[1]"
        set from (echo $argv[1] | trim-right /)
        set to (echo $argv[2])
        command cp -r $from $to
    else
        command cp $argv
    end
end

set -U fish_complete_path $fish_complete_path /nix/var/nix/profiles/default/share/fish/vendor_completions.d
set -Ux EDITOR nvim
set -U fish_history_max 1000

{{ if eq .chezmoi.hostname "ubuntu" }}
    fish_add_path /opt/nvim-linux-x86_64/bin
{{ end }}

alias vim='nvim'
alias cd='z'
alias ls='eza --icons=always --color=always'
alias untar='tar -zxvf '
alias grep='grep --color=auto'
alias cleanup='sudo pacman -Rns (pacman -Qtdq)'

chezmoi completion fish | source
direnv hook fish | source
zoxide init fish | source
starship init fish | source
t .kt { color: #66d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #ff4689 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #ff4689 } /* Operator.Word */ .highlight .pm { color: #f8f8f2 } /* Punctuation.Marker */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("vim-options")
require("lazy").setup("plugins")

vim.o.number = true
vim.o.relativenumber = true

vim.filetype.add({
  extension = {
    gotmpl = 'gotmpl',
  },
  pattern = {
    [".*%.gohtml"] = "gotmpl",
    [".*%.gotmpl"] = "gotmpl"
  }
})

-- Panes
vim.cmd.set("splitright")
vim.keymap.set("n", "<leader>/", function()
  vim.cmd.vnew()
end, { desc = "Pane split right" })

vim.cmd.set("splitbelow")
vim.keymap.set("n", "<leader>-", function()
  vim.cmd.new()
end, { desc = "Pane split down" })

local function smart_move(direction, vim_cmd)
  return function()
    local before = vim.api.nvim_get_current_win()

    vim.cmd("wincmd " .. vim_cmd)

    if before == vim.api.nvim_get_current_win() then
      vim.system({
        "hyprctl",
        "dispatch",
        string.format(
          "hl.dsp.focus({direction = '%s' })",
          direction
        )
      })
    end
  end
end

vim.keymap.set('n', '<D-h>', smart_move("left", "h"), { noremap = true, silent = false, desc = "Move to left windows" });
vim.keymap.set('n', '<D-l>', smart_move("right", "l"), { noremap = true, silent = false, desc = "Move to right windows" });
vim.keymap.set('n', '<D-j>', smart_move("down", "j"), { noremap = true, silent = false, desc = "Move to down window" });
vim.keymap.set('n', '<D-k>', smart_move("up", "k"), { noremap = true, silent = false, desc = "Move to up window" });

vim.api.nvim_set_keymap('n', 'gb', ':bnext<CR>', { noremap = true, silent = true, desc = "Go back last buffer" });

vim.api.nvim_set_keymap('t', '<c-[><c-[>', '<C-\\><C-n>', { noremap = true, silent = true, desc = "Escape Terminal" });
vim.api.nvim_create_autocmd('TermOpen', {
  group = vim.api.nvim_create_augroup('custom-term-open', { clear = true }),
  callback = function()
    vim.opt.number = false
    vim.opt.relativenumber = false
  end,
});


-- Telescope
local builtin = require("telescope.builtin")
vim.keymap.set('n', '<leader>fg', function() builtin.live_grep({ glob_pattern = "!*_templ.go" }) end,
  { desc = "Telescope live grep" })
vim.keymap.set('n', 'gl', builtin.lsp_references, { desc = "Telescope show references" })
vim.keymap.set('n', '<leader>fx', builtin.diagnostics, { desc = "Telescope open diagnostics" })
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = "Telescope find files" })
vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = "Telescope open buffers" })

-- Formating
vim.keymap.set("n", "<leader>gf", function()
  require("conform").format({ lsp_format = "fallback" })
end, { desc = "Format buffer" })

-- Filesystem
vim.keymap.set("n", "<leader>e", ":Oil<CR>", { desc = "Open file explorer: OIL" })

-- Neotest
local neotest = require("neotest")
vim.keymap.set("n", "<leader>ts", function()
  neotest.summary.toggle()
end, { desc = "Neotest open summary" })
vim.keymap.set("n", "<leader>to", neotest.output.open, { desc = "Neotest open output" })
vim.keymap.set("n", "<leader>td", function() neotest.run.run({ suite = false, strategy = "dap" }) end,
  { desc = "Neotest debug closest test" })
vim.keymap.set("n", "<leader>tr", function() neotest.run.run({ suite = false }) end,
  { desc = "Neotest run closest test" })

-- Debugging
local dap = require("dap")
vim.keymap.set("n", "<leader>db", dap.toggle_breakpoint,
  { nowait = true, remap = false, desc = "Debug toggle breakpoint" })
vim.keymap.set("n", "<leader>dc", dap.continue, { nowait = true, remap = false, desc = "Debug continue" })
vim.keymap.set("n", "<leader>di", dap.step_into, { nowait = true, remap = false, desc = "Debug step into" })
vim.keymap.set("n", "<leader>do", dap.step_over, { nowait = true, remap = false, desc = "Debug step over" })
vim.keymap.set("n", "<leader>dr", dap.repl.open, { nowait = true, remap = false, desc = "Debug open repl" })
vim.keymap.set("n", "<leader>dq", function()
  dap.terminate()
  require("dapui").close()
  require("nvim-dap-virtual-text").toggle()
end, { nowait = true, remap = false, desc = "Debug close" })
vim.keymap.set("n", "<leader>dl", dap.list_breakpoints, { nowait = true, remap = false, desc = "Debug list breakpoints" })

local function read_pyproject()
  local results = vim.fs.find("pyproject.toml", { upward = true, stop = vim.loop.os_homedir() })
  local path = results[1]
  if not path then
    return nil
  end

  local ok, lines = pcall(vim.fn.readfile, path)
  if not ok then
    return nil
  end

  return table.concat(lines, "\n")
end

local function get_scripts_from_pyproject()
  local pyproject = read_pyproject()
  if not pyproject then
    return {}
  end

  local scripts = {}

  -- Match [tool.poetry.scripts]
  for script_line in pyproject:gmatch("%[tool%.poetry%.scripts%][^\n]*\n([^%[]*)") do
    for name, module in script_line:gmatch('([%w_%-]+)%s*=%s*"([^"]+)"') do
      scripts[name] = module
    end
  end

  -- Match [project.scripts]
  for script_line in pyproject:gmatch("%[project%.scripts%][^\n]*\n([^%[]*)") do
    for name, module in script_line:gmatch('([%w_%-]+)%s*=%s*"([^"]+)"') do
      scripts[name] = module
    end
  end

  return scripts
end

local function get_python_path()
  local cwd = vim.fn.getcwd()
  if vim.fn.executable(cwd .. "/venv/bin/python") == 1 then
    return cwd .. "/venv/bin/python"
  elseif vim.fn.executable(cwd .. "/.venv/bin/python") == 1 then
    return cwd .. "/.venv/bin/python"
  else
    return vim.fn.exepath("python")
  end
end

-- Store last used parameters for quick reuse
local last_params = {}

vim.keymap.set("n", "<leader>dps", function()
  local scripts = get_scripts_from_pyproject()

  if vim.tbl_isempty(scripts) then
    vim.notify("No scripts found in pyproject.toml", vim.log.levels.WARN)
    return
  end

  local script_names = vim.tbl_keys(scripts)
  table.sort(script_names)

  local function start_debug(script_name, module, args_str)
    local package = module:match("^([^:]+)")

    -- Parse arguments string into table
    local args = {}
    if args_str and args_str ~= "" then
      for arg in args_str:gmatch("%S+") do
        table.insert(args, arg)
      end
    end

    -- Store for quick reuse
    last_params[script_name] = args_str or ""

    vim.notify(
      "Debugging: " .. script_name .. (args_str and (" with args: " .. args_str) or ""),
      vim.log.levels.INFO
    )

    local dap = require("dap")
    dap.configurations.python = {
      {
        type = "python",
        request = "launch",
        name = "Debug: " .. script_name,
        module = package,
        args = args,
        pythonPath = get_python_path(),
        justMyCode = false,
        console = "integratedTerminal",
      },
    }
    dap.continue()
  end

  local function show_param_input(script_name, module)
    -- Show input dialog for parameters
    vim.ui.input({
      prompt = "Arguments for " .. script_name .. ": ",
      default = last_params[script_name] or "",
      completion = "file",
    }, function(args_str)
      if args_str ~= nil then -- nil = cancelled, "" = empty input is OK
        start_debug(script_name, module, args_str)
      end
    end)
  end

  local function select_script()
    if #script_names == 1 then
      show_param_input(script_names[1], scripts[script_names[1]])
    else
      vim.ui.select(script_names, {
        prompt = "Select script to debug: ",
        format_item = function(item)
          return item .. " → " .. scripts[item]
        end,
      }, function(selected)
        if selected then
          show_param_input(selected, scripts[selected])
        end
      end)
    end
  end

  select_script()
end, { desc = "Debug Python script from pyproject.toml" })
-- Lsp Config
vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Show hover information" })
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Goto definition" })
vim.keymap.set({ "n", "v" }, "<leader>ca", vim.lsp.buf.code_action, { desc = "LSP code action" })
vim.keymap.set("n", "<leader>cr", vim.lsp.buf.rename, { desc = "LSP rename" })

-- Motions
vim.keymap.set("n", "<C-d>", "<C-d>zz", {})
vim.keymap.set("n", "<C-u>", "<C-u>zz", {})