From 1474caa8f624aa568ea011629d1aec4ae2aca3c1 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar <54011232+arpitchakladar@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:03:12 +0530 Subject: Using fzf as the application launcher. --- home.nix | 7 +- modules/desktop/application-launcher/default.nix | 24 +++++++ .../desktop/application-launcher/fzf/default.nix | 22 ++++++ modules/desktop/application-launcher/fzf/launch.sh | 10 +++ .../desktop/application-launcher/rofi/default.nix | 20 ++++++ .../application-launcher/rofi/theme.mustache.rasi | 82 ++++++++++++++++++++++ modules/desktop/default.nix | 2 +- modules/desktop/popup-manager/default.nix | 14 ---- modules/desktop/popup-manager/rofi/default.nix | 16 ----- .../desktop/popup-manager/rofi/theme.mustache.rasi | 82 ---------------------- modules/desktop/window-manager/bspwm/default.nix | 2 +- modules/desktop/window-manager/sxhkd/default.nix | 4 +- modules/shell/bash/default.nix | 5 ++ modules/shell/zsh/default.nix | 7 +- modules/tools/default.nix | 3 +- modules/tools/editor/neovim/config/keybindings.lua | 3 - modules/tools/editor/neovim/config/options.lua | 16 ++--- .../tools/editor/neovim/plugins/config/default.nix | 1 + .../editor/neovim/plugins/config/dressing.lua | 1 + .../editor/neovim/plugins/config/lsp-config.lua | 17 ++--- .../editor/neovim/plugins/config/nvim-tree.lua | 2 + modules/tools/editor/neovim/plugins/default.nix | 2 + modules/tools/file-manager/nnn/default.nix | 13 ++-- modules/tools/fzf/default.nix | 35 +++++++++ modules/tools/git/default.nix | 12 +++- 25 files changed, 257 insertions(+), 145 deletions(-) create mode 100644 modules/desktop/application-launcher/default.nix create mode 100644 modules/desktop/application-launcher/fzf/default.nix create mode 100644 modules/desktop/application-launcher/fzf/launch.sh create mode 100644 modules/desktop/application-launcher/rofi/default.nix create mode 100644 modules/desktop/application-launcher/rofi/theme.mustache.rasi delete mode 100644 modules/desktop/popup-manager/default.nix delete mode 100644 modules/desktop/popup-manager/rofi/default.nix delete mode 100644 modules/desktop/popup-manager/rofi/theme.mustache.rasi create mode 100644 modules/tools/editor/neovim/plugins/config/dressing.lua create mode 100644 modules/tools/fzf/default.nix diff --git a/home.nix b/home.nix index bf98638..d7776e4 100644 --- a/home.nix +++ b/home.nix @@ -7,7 +7,9 @@ # Desktop desktop.display-server.x11.xinit.enable = true; - desktop.popup-manager.rofi.enable = true; + desktop.application-launcher.rofi.enable = true; + desktop.application-launcher.fzf.enable = true; + desktop.application-launcher.default = "fzf"; desktop.status-bar.polybar.enable = true; desktop.terminal.alacritty.enable = true; desktop.terminal.kitty.enable = true; @@ -31,7 +33,10 @@ tools.file-manager.nnn.enable = true; tools.file-manager.default = "nnn"; tools.file-manager.lsd.enable = true; + tools.fzf.enable = true; tools.git.enable = true; + tools.git.username = "Arpit Chakladar"; + tools.git.email = "54011232+arpitchakladar@users.noreply.github.com"; tools.system-monitor.htop.enable = true; tools.viewer.bat.enable = true; diff --git a/modules/desktop/application-launcher/default.nix b/modules/desktop/application-launcher/default.nix new file mode 100644 index 0000000..3abb908 --- /dev/null +++ b/modules/desktop/application-launcher/default.nix @@ -0,0 +1,24 @@ +{ lib, ... }: + +{ + imports = [ + ./fzf + ./rofi + ]; + + options.desktop.application-launcher = { + default = lib.mkOption { + type = lib.types.enum [ + "fzf" + "rofi" + ]; + + description = "Select the default application launcher."; + }; + + command = lib.mkOption { + type = lib.types.str; + description = "Command for default application launcher program."; + }; + }; +} diff --git a/modules/desktop/application-launcher/fzf/default.nix b/modules/desktop/application-launcher/fzf/default.nix new file mode 100644 index 0000000..0196a2b --- /dev/null +++ b/modules/desktop/application-launcher/fzf/default.nix @@ -0,0 +1,22 @@ +{ config, lib, pkgs, ... }: + +{ + options.desktop.application-launcher.fzf = { + enable = lib.mkEnableOption "Enables fzf to be used as a application launcher."; + }; + + config = lib.mkIf config.desktop.application-launcher.fzf.enable { + assertions = [ + { + assertion = config.tools.fzf.enable; + message ="Module desktop.application-launcher.fzf requires tools.fzf module to be enabled."; + } + ]; + + desktop.application-launcher.default = lib.mkDefault "fzf"; + desktop.application-launcher.command = + if config.desktop.application-launcher.default == "fzf" then + lib.mkForce "${config.desktop.terminal.command} --title 'Application Launcher' --class floating-termial -e ${(pkgs.writeShellScript "fzf-launch.sh" (builtins.readFile ./launch.sh))}" + else ""; + }; +} diff --git a/modules/desktop/application-launcher/fzf/launch.sh b/modules/desktop/application-launcher/fzf/launch.sh new file mode 100644 index 0000000..16e2565 --- /dev/null +++ b/modules/desktop/application-launcher/fzf/launch.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +selected_executable=$(find -L $(echo $PATH | tr ':' ' ') -maxdepth 1 -executable -type f 2>/dev/null | xargs -n 1 basename | sort -u | fzf --height=100% --layout=reverse --prompt " ") + +if [[ -n "$selected_executable" ]]; then + setsid "$selected_executable" >/dev/null 2>&1 & + disown + sleep + kill -9 $PPID +fi diff --git a/modules/desktop/application-launcher/rofi/default.nix b/modules/desktop/application-launcher/rofi/default.nix new file mode 100644 index 0000000..58a64a4 --- /dev/null +++ b/modules/desktop/application-launcher/rofi/default.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +{ + options.desktop.application-launcher.rofi = { + enable = lib.mkEnableOption "Enables rofi."; + }; + + config = lib.mkIf config.desktop.application-launcher.rofi.enable { + desktop.application-launcher.default = lib.mkDefault "rofi"; + desktop.application-launcher.command = + if config.desktop.application-launcher.default == "rofi" then + lib.mkForce "${pkgs.rofi}/bin/rofi -show run" + else ""; + programs.rofi.enable = true; + programs.rofi.font = "${config.fonts.normal} ${toString config.fonts.size}"; + programs.rofi.theme = config.scheme { + template = builtins.readFile ./theme.mustache.rasi; + }; + }; +} diff --git a/modules/desktop/application-launcher/rofi/theme.mustache.rasi b/modules/desktop/application-launcher/rofi/theme.mustache.rasi new file mode 100644 index 0000000..02cdaf3 --- /dev/null +++ b/modules/desktop/application-launcher/rofi/theme.mustache.rasi @@ -0,0 +1,82 @@ +configuration { + drun { + display-name: " "; + } + + run { + display-name: " "; + } + + window { + display-name: " "; + } + + ssh { + display-name: " "; + } + + timeout { + delay: 10; + action: "kb-cancel"; + } +} + +* { + border: 1; + margin: 0; + padding: 0; + spacing: 0; + + bg: #{{base00-hex}}; + bg-alt: #{{base01-hex}}; + fg: #{{base07-hex}}; + fg-alt: #{{base03-hex}}; + + background-color: @bg; + text-color: @fg; +} + +window { + transparency: "real"; + border-color: #{{base03-hex}}; +} + +mainbox { + children: [inputbar, listview]; +} + +inputbar { + background-color: @bg-alt; + children: [prompt, entry]; +} + +entry { + background-color: inherit; + padding: 12px 3px; +} + +prompt { + background-color: inherit; + padding: 12px; +} + +listview { + lines: 8; +} + +element { + children: [element-text]; +} + +element-icon { + padding: 10px 10px; +} + +element-text { + padding: 10px 10px; + text-color: @fg-alt; +} + +element-text selected { + text-color: @fg; +} diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index bae73fc..43ef865 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -2,8 +2,8 @@ { imports = [ + ./application-launcher ./display-server - ./popup-manager ./status-bar ./terminal ./window-manager diff --git a/modules/desktop/popup-manager/default.nix b/modules/desktop/popup-manager/default.nix deleted file mode 100644 index c34d29d..0000000 --- a/modules/desktop/popup-manager/default.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ lib, ... }: - -{ - imports = [ - ./rofi - ]; - - options.desktop.popup-manager = { - application-launcher.command = lib.mkOption { - type = lib.types.str; - description = "Command for default application launcher program."; - }; - }; -} diff --git a/modules/desktop/popup-manager/rofi/default.nix b/modules/desktop/popup-manager/rofi/default.nix deleted file mode 100644 index 1ddc208..0000000 --- a/modules/desktop/popup-manager/rofi/default.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - options.desktop.popup-manager.rofi = { - enable = lib.mkEnableOption "Enables rofi."; - }; - - config = lib.mkIf config.desktop.popup-manager.rofi.enable { - desktop.popup-manager.application-launcher.command = "${pkgs.rofi}/bin/rofi -show run"; - programs.rofi.enable = true; - programs.rofi.font = "${config.fonts.normal} ${toString config.fonts.size}"; - programs.rofi.theme = config.scheme { - template = builtins.readFile ./theme.mustache.rasi; - }; - }; -} diff --git a/modules/desktop/popup-manager/rofi/theme.mustache.rasi b/modules/desktop/popup-manager/rofi/theme.mustache.rasi deleted file mode 100644 index 02cdaf3..0000000 --- a/modules/desktop/popup-manager/rofi/theme.mustache.rasi +++ /dev/null @@ -1,82 +0,0 @@ -configuration { - drun { - display-name: " "; - } - - run { - display-name: " "; - } - - window { - display-name: " "; - } - - ssh { - display-name: " "; - } - - timeout { - delay: 10; - action: "kb-cancel"; - } -} - -* { - border: 1; - margin: 0; - padding: 0; - spacing: 0; - - bg: #{{base00-hex}}; - bg-alt: #{{base01-hex}}; - fg: #{{base07-hex}}; - fg-alt: #{{base03-hex}}; - - background-color: @bg; - text-color: @fg; -} - -window { - transparency: "real"; - border-color: #{{base03-hex}}; -} - -mainbox { - children: [inputbar, listview]; -} - -inputbar { - background-color: @bg-alt; - children: [prompt, entry]; -} - -entry { - background-color: inherit; - padding: 12px 3px; -} - -prompt { - background-color: inherit; - padding: 12px; -} - -listview { - lines: 8; -} - -element { - children: [element-text]; -} - -element-icon { - padding: 10px 10px; -} - -element-text { - padding: 10px 10px; - text-color: @fg-alt; -} - -element-text selected { - text-color: @fg; -} diff --git a/modules/desktop/window-manager/bspwm/default.nix b/modules/desktop/window-manager/bspwm/default.nix index b2aa1ce..c69a54b 100644 --- a/modules/desktop/window-manager/bspwm/default.nix +++ b/modules/desktop/window-manager/bspwm/default.nix @@ -33,7 +33,7 @@ }; xsession.windowManager.bspwm.rules = { - "popup" = { + "floating-termial" = { state = "floating"; sticky = true; rectangle = "1000x600+0+0"; diff --git a/modules/desktop/window-manager/sxhkd/default.nix b/modules/desktop/window-manager/sxhkd/default.nix index c31604b..6e5d9bb 100644 --- a/modules/desktop/window-manager/sxhkd/default.nix +++ b/modules/desktop/window-manager/sxhkd/default.nix @@ -29,7 +29,7 @@ ${(createKeybinding "r" "Application launcher.")} - = config.desktop.popup-manager.application-launcher.command; + = config.desktop.application-launcher.command; ${(createKeybinding "t" @@ -39,7 +39,7 @@ ${(createKeybinding "f" "Launch File Manager.")} - = "${config.desktop.terminal.command} --title 'File Manager' --class popup -e ${config.tools.file-manager.command}"; + = "${config.desktop.terminal.command} --title 'File Manager' --class floating-termial -e ${config.tools.file-manager.command}"; } ]; }; diff --git a/modules/shell/bash/default.nix b/modules/shell/bash/default.nix index a82f924..fb1040a 100644 --- a/modules/shell/bash/default.nix +++ b/modules/shell/bash/default.nix @@ -19,6 +19,11 @@ programs.bash.enable = true; programs.bash.historyFile = "${config.xdg.cacheHome}/bash/history"; programs.bash.shellAliases = config.shell.alias; + programs.bash.bashrcExtra = '' +${if config.tools.fzf.enable then + "eval \"$(fzf --bash)\"" +else ""} + ''; home.activation.createBashCacheDirectory = lib.hm.dag.entryAfter diff --git a/modules/shell/zsh/default.nix b/modules/shell/zsh/default.nix index 0c14b8c..66e9556 100644 --- a/modules/shell/zsh/default.nix +++ b/modules/shell/zsh/default.nix @@ -15,7 +15,12 @@ programs.zsh.enable = true; programs.zsh.dotDir = ".config/zsh"; programs.zsh.history.path = "${config.xdg.cacheHome}/zsh/history"; - programs.zsh.initExtra = builtins.readFile ./zshrc; programs.zsh.shellAliases = config.shell.alias; + programs.zsh.initExtra = '' +${if config.tools.fzf.enable then + "eval \"$(fzf --zsh)\"" +else ""} +${builtins.readFile ./zshrc} + ''; }; } diff --git a/modules/tools/default.nix b/modules/tools/default.nix index bf96557..266e900 100644 --- a/modules/tools/default.nix +++ b/modules/tools/default.nix @@ -1,9 +1,10 @@ -{ lib, config, ... }: +{ ... }: { imports = [ ./editor ./file-manager + ./fzf ./git ./system-monitor ./viewer diff --git a/modules/tools/editor/neovim/config/keybindings.lua b/modules/tools/editor/neovim/config/keybindings.lua index 3e8e0fa..3f2c9bf 100644 --- a/modules/tools/editor/neovim/config/keybindings.lua +++ b/modules/tools/editor/neovim/config/keybindings.lua @@ -3,6 +3,3 @@ vim.keymap.set("n", "", ":wincmd h", { silent = true }); vim.keymap.set("n", "", ":wincmd j", { silent = true }); vim.keymap.set("n", "", ":wincmd k", { silent = true }); vim.keymap.set("n", "", ":wincmd l", { silent = true }); - --- NvimTree -vim.keymap.set("n", "", ":NvimTreeToggle", { silent = true }); diff --git a/modules/tools/editor/neovim/config/options.lua b/modules/tools/editor/neovim/config/options.lua index 450e613..bd475c7 100644 --- a/modules/tools/editor/neovim/config/options.lua +++ b/modules/tools/editor/neovim/config/options.lua @@ -31,11 +31,11 @@ vim.api.nvim_create_autocmd("FileType", { }); -- Exception that use spaces --- vim.api.nvim_create_autocmd("FileType", { --- pattern = {}, --- callback = function() --- vim.bo.expandtab = true; --- vim.bo.tabstop = 2; --- vim.bo.shiftwidth = 2; --- end, --- }); +vim.api.nvim_create_autocmd("FileType", { + pattern = { "yaml" }, + callback = function() + vim.bo.expandtab = true; + vim.bo.tabstop = 2; + vim.bo.shiftwidth = 2; + end, +}); diff --git a/modules/tools/editor/neovim/plugins/config/default.nix b/modules/tools/editor/neovim/plugins/config/default.nix index 6dff0b9..81407d7 100644 --- a/modules/tools/editor/neovim/plugins/config/default.nix +++ b/modules/tools/editor/neovim/plugins/config/default.nix @@ -4,6 +4,7 @@ let extra = if config.tools.editor.neovim.configuration == "full" then '' ${builtins.readFile ./lsp-config.lua} +${builtins.readFile ./dressing.lua} ${builtins.readFile (config.scheme { template = builtins.readFile ./noice.mustache.lua; })} diff --git a/modules/tools/editor/neovim/plugins/config/dressing.lua b/modules/tools/editor/neovim/plugins/config/dressing.lua new file mode 100644 index 0000000..6d14d47 --- /dev/null +++ b/modules/tools/editor/neovim/plugins/config/dressing.lua @@ -0,0 +1 @@ +require("dressing").setup(); diff --git a/modules/tools/editor/neovim/plugins/config/lsp-config.lua b/modules/tools/editor/neovim/plugins/config/lsp-config.lua index 88f063d..d440c67 100644 --- a/modules/tools/editor/neovim/plugins/config/lsp-config.lua +++ b/modules/tools/editor/neovim/plugins/config/lsp-config.lua @@ -45,23 +45,24 @@ local lsp_setup_done = {}; -- Function to setup LSP based on filetype local function setup_lsp(filetype) local lsp = filetype_to_lsp[filetype]; - if lsp and not lsp_setup_done[lsp.server] then + if lsp ~= nil and not lsp_setup_done[lsp.server] then lsp_setup_done[lsp.server] = true; - if vim.fn.executable(lsp.executable) then + if vim.fn.executable(lsp.executable) == 1 then lspconfig[lsp.server].setup({}); - vim.lsp.start(); end end end -vim.keymap.set("n", "gd", vim.lsp.buf.definition, { noremap = true, silent = true }); -vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { noremap = true, silent = true }); -vim.keymap.set("n", "gr", vim.lsp.buf.references, { noremap = true, silent = true }); -vim.keymap.set("n", "gk", vim.lsp.buf.hover, { noremap = true, silent = true }); - vim.api.nvim_create_autocmd("FileType", { pattern = "*", -- Match all file types callback = function() setup_lsp(vim.bo.filetype); -- Call the setup_lsp function only if the filetype is in the mapping end, }); + +local lsp_keymap_opts = { noremap = true, silent = true }; + +vim.keymap.set("n", "d", vim.lsp.buf.definition, lsp_keymap_opts); +vim.keymap.set("n", "i", vim.lsp.buf.implementation, lsp_keymap_opts); +vim.keymap.set("n", "r", vim.lsp.buf.references, lsp_keymap_opts); +vim.keymap.set("n", "k", vim.lsp.buf.hover, lsp_keymap_opts); diff --git a/modules/tools/editor/neovim/plugins/config/nvim-tree.lua b/modules/tools/editor/neovim/plugins/config/nvim-tree.lua index c6c4102..cdbef6a 100644 --- a/modules/tools/editor/neovim/plugins/config/nvim-tree.lua +++ b/modules/tools/editor/neovim/plugins/config/nvim-tree.lua @@ -11,3 +11,5 @@ require("nvim-tree").setup { end, }, }; + +vim.keymap.set("n", "", ":NvimTreeToggle", { silent = true }); diff --git a/modules/tools/editor/neovim/plugins/default.nix b/modules/tools/editor/neovim/plugins/default.nix index d2a58b1..61c046c 100644 --- a/modules/tools/editor/neovim/plugins/default.nix +++ b/modules/tools/editor/neovim/plugins/default.nix @@ -10,6 +10,7 @@ nvim-treesitter nvim-web-devicons nvim-tree-lua + which-key-nvim (base16-vim.overrideAttrs (old: { patchPhase = "ln -s ${config.scheme base16-vim} colors/base16-scheme.vim"; })) @@ -17,6 +18,7 @@ (if config.tools.editor.neovim.configuration == "full" then [ noice-nvim + dressing-nvim nvim-lspconfig ] else null) diff --git a/modules/tools/file-manager/nnn/default.nix b/modules/tools/file-manager/nnn/default.nix index 73b5c9d..7426153 100644 --- a/modules/tools/file-manager/nnn/default.nix +++ b/modules/tools/file-manager/nnn/default.nix @@ -5,16 +5,19 @@ enable = lib.mkEnableOption "Enables nnn."; }; - config = lib.mkIf config.tools.file-manager.nnn.enable { + config = + let + nnnWithNerdIcons = pkgs.nnn.override ({ withNerdIcons = true; }); + in lib.mkIf config.tools.file-manager.nnn.enable { tools.file-manager.default = lib.mkDefault "nnn"; tools.file-manager.command = if config.tools.file-manager.default == "nnn" then - lib.mkForce "${pkgs.nnn}/bin/nnn -H -d" + lib.mkForce "${nnnWithNerdIcons}/bin/nnn -H -d" else ""; programs.nnn.enable = true; - programs.nnn.package = pkgs.nnn.override ({ withNerdIcons = true; }); - programs.nnn.plugins.src = "${pkgs.nnn}/share/plugins"; - shell.alias."nnn" = "nnn -H -d"; + programs.nnn.package = nnnWithNerdIcons; + programs.nnn.plugins.src = "${nnnWithNerdIcons}/share/plugins"; + shell.alias."nnn" = "${nnnWithNerdIcons}/bin/nnn -H -d"; }; } diff --git a/modules/tools/fzf/default.nix b/modules/tools/fzf/default.nix new file mode 100644 index 0000000..5ed8442 --- /dev/null +++ b/modules/tools/fzf/default.nix @@ -0,0 +1,35 @@ +{ config, lib,... }: + +{ + options.tools.fzf = { + enable = lib.mkEnableOption "Enables fzf."; + }; + + config = lib.mkIf config.tools.fzf.enable { + programs.fzf.enable = true; + programs.fzf.defaultOptions = [ + "--height 40%" + "--layout=reverse" + (if config.fonts.nerdfont.fira-code.enable then "--pointer=\"\"" else "--pointer=\">\"") + "--header=\" \"" + "--border=none" + ]; + + programs.fzf.colors = with config.scheme.withHashtag; { + fg = base05; # Foreground + bg = base00; # Background + hl = base0D; # Highlight + + "fg+" = base07; # Foreground for selected item + "bg+" = base01; # Background for selected item + "hl+" = base0D; # Highlight for selected item + + info = base0B; # Info text (usually count of items) + border = base03; # Border color + prompt = base0A; # Prompt text color + pointer = base07; # Pointer color (e.g., > for selected) + marker = base0C; # Marker color (e.g., for multi-select) + spinner = base0C; # Spinner color (during search) + }; + }; +} diff --git a/modules/tools/git/default.nix b/modules/tools/git/default.nix index 135cbc6..798db39 100644 --- a/modules/tools/git/default.nix +++ b/modules/tools/git/default.nix @@ -3,12 +3,20 @@ { options.tools.git = { enable = lib.mkEnableOption "Enables git."; + username = lib.mkOption { + type = lib.types.str; + description = "Github username."; + }; + email = lib.mkOption { + type = lib.types.str; + description = "Github email."; + }; }; config = lib.mkIf config.tools.git.enable { programs.git.enable = true; - programs.git.userEmail = "54011232+arpitchakladar@users.noreply.github.com"; - programs.git.userName = "Arpit Chakladar"; + programs.git.userName = config.tools.git.username; + programs.git.userEmail = config.tools.git.email; programs.git.extraConfig = { credential.helper = "store --file ${config.xdg.cacheHome}/git/credential"; core.askPass = ""; -- cgit v1.2.3