From 495bb98edbfa8aaf3d44d60f3888848b82a8e989 Mon Sep 17 00:00:00 2001 From: C4 Patino Date: Fri, 4 Jul 2025 08:34:35 -0500 Subject: [PATCH] refactor: extracted alpha shortcut creation into its own function --- config/ui/alpha.nix | 198 ++++++++++---------------------------------- 1 file changed, 42 insertions(+), 156 deletions(-) diff --git a/config/ui/alpha.nix b/config/ui/alpha.nix index 5695cc5..9d8e7ad 100755 --- a/config/ui/alpha.nix +++ b/config/ui/alpha.nix @@ -3,12 +3,40 @@ enable = true; theme = null; layout = let - padding = val: { + mkPadding = val: { type = "padding"; inherit val; }; + mkButton = label: shortcut: command: { + type = "button"; + val = label; + on_press.__raw = '' + function() + local key = vim.api.nvim_replace_termcodes("${shortcut}", true, false, true) + vim.api.nvim_feedkeys(key, "n", false) + end + ''; + opts = { + keymap = [ + "n" + shortcut + command + { + noremap = true; + silent = true; + nowait = true; + } + ]; + shortcut = shortcut; + position = "center"; + cursor = 3; + width = 38; + align_shortcut = "right"; + hl_shortcut = "Keyword"; + }; + }; in [ - (padding 4) + (mkPadding 4) { opts = { hl = "AlphaHeader"; @@ -29,160 +57,18 @@ " git@github.com:c4patino " ]; } - (padding 2) - { - type = "button"; - val = " Find File"; - on_press = { - __raw = "function() require('telescope.builtin').find_files() end"; - }; - opts = { - keymap = [ - "n" - "f" - ":Telescope find_files " - { - noremap = true; - silent = true; - nowait = true; - } - ]; - shortcut = "f"; - - position = "center"; - cursor = 3; - width = 38; - align_shortcut = "right"; - hl_shortcut = "Keyword"; - }; - } - (padding 1) - { - type = "button"; - val = " New File"; - on_press = { - __raw = "function() vim.cmd[[ene]] end"; - }; - opts = { - keymap = [ - "n" - "n" - ":ene startinsert " - { - noremap = true; - silent = true; - nowait = true; - } - ]; - shortcut = "n"; - - position = "center"; - cursor = 3; - width = 38; - align_shortcut = "right"; - hl_shortcut = "Keyword"; - }; - } - (padding 1) - { - type = "button"; - val = "󰈚 Recent Files"; - on_press.__raw = "function() require('telescope.builtin').oldfiles() end"; - opts = { - keymap = [ - "n" - "r" - ":Telescope oldfiles " - { - noremap = true; - silent = true; - nowait = true; - } - ]; - shortcut = "r"; - - position = "center"; - cursor = 3; - width = 38; - align_shortcut = "right"; - hl_shortcut = "Keyword"; - }; - } - (padding 1) - { - type = "button"; - val = "󰈭 Find Word"; - on_press.__raw = "function() require('telescope.builtin').live_grep() end"; - opts = { - keymap = [ - "n" - "g" - ":Telescope live_grep " - { - noremap = true; - silent = true; - nowait = true; - } - ]; - shortcut = "g"; - - position = "center"; - cursor = 3; - width = 38; - align_shortcut = "right"; - hl_shortcut = "Keyword"; - }; - } - (padding 1) - { - type = "button"; - val = " Restore Session"; - on_press.__raw = "function() require('persistence').load() end"; - opts = { - keymap = [ - "n" - "s" - ":lua require('persistence').load()" - { - noremap = true; - silent = true; - nowait = true; - } - ]; - shortcut = "s"; - - position = "center"; - cursor = 3; - width = 38; - align_shortcut = "right"; - hl_shortcut = "Keyword"; - }; - } - (padding 1) - { - type = "button"; - val = " Quit Neovim"; - on_press.__raw = "function() vim.cmd[[qa]] end"; - opts = { - keymap = [ - "n" - "q" - ":qa" - { - noremap = true; - silent = true; - nowait = true; - } - ]; - shortcut = "q"; - - position = "center"; - cursor = 3; - width = 38; - align_shortcut = "right"; - hl_shortcut = "Keyword"; - }; - } + (mkPadding 2) + (mkButton " Find File" "f" "Telescope find_files") + (mkPadding 1) + (mkButton " New File" "n" "ene startinsert") + (mkPadding 1) + (mkButton "󰈚 Recent Files" "r" "Telescope oldfiles") + (mkPadding 1) + (mkButton "󰈭 Find Word" "g" "Telescope live_grep") + (mkPadding 1) + (mkButton " Restore Session" "s" "lua require('persistence').load()") + (mkPadding 1) + (mkButton " Quit Neovim" "q" "qa") ]; }; }