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. --- 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 +- 11 files changed, 162 insertions(+), 116 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 (limited to 'modules/desktop') 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}"; } ]; }; -- cgit v1.2.3