From 1a39cf221e3f647df0767c88d89a54e3813e7019 Mon Sep 17 00:00:00 2001 From: Arpit Chakladar Date: Sat, 29 Aug 2026 03:45:10 +0530 Subject: refactor: adding explicit options to enable scripts - some scripts that are not critical to the functioning of other options, can be enabled/disabled --- modules/file-management/yazi/default.nix | 33 +++++++++++++---------- modules/file-management/yazi/file-chooser.sh | 21 +++++++++++++++ modules/file-management/yazi/yazi-file-chooser.sh | 21 --------------- 3 files changed, 40 insertions(+), 35 deletions(-) create mode 100644 modules/file-management/yazi/file-chooser.sh delete mode 100644 modules/file-management/yazi/yazi-file-chooser.sh (limited to 'modules/file-management') diff --git a/modules/file-management/yazi/default.nix b/modules/file-management/yazi/default.nix index d704614..2f7c44f 100644 --- a/modules/file-management/yazi/default.nix +++ b/modules/file-management/yazi/default.nix @@ -6,22 +6,14 @@ ... }: let - inherit ((import ../../lib/script.nix { inherit lib pkgs; })) mkScriptModule; - yaziFileChooser = mkScriptModule { - scope = [ - "file-management" - "yazi" - ]; + yaziFileChooserScript = pkgs.writeShellApplication { name = "yazi-file-chooser"; - path = ./yazi-file-chooser.sh; - description = "Yazi-based file chooser for XDG Desktop Portal"; - deps = [ + runtimeInputs = [ pkgs.bash config.file-management.yazi.package config.terminal.kitty.package ]; - extraLinks = [ "~/.config/xdg-desktop-portal-termfilechooser/config" ]; - inherit config; + text = builtins.readFile ./file-chooser.sh; }; in { @@ -39,8 +31,17 @@ in defaultText = lib.literalExpression "config.programs.yazi.finalPackage"; description = "The yazi package to use. Defaults to the wrapped finalPackage from programs.yazi."; }; - } - // yaziFileChooser.options.file-management.yazi; + + file-chooser = { + enable = lib.mkEnableOption "Enables the yazi-file-chooser script."; + package = lib.mkOption { + type = lib.types.package; + readOnly = true; + default = yaziFileChooserScript; + description = "The yazi-file-chooser script package."; + }; + }; + }; config = lib.mkMerge [ (lib.mkIf config.file-management.yazi.enable { @@ -77,6 +78,10 @@ in TERMCMD = lib.mkIf config.terminal.kitty.enable "${lib.getExe config.terminal.kitty.package} --class file-explorer --title 'Yazi'"; }; }) - yaziFileChooser.config + (lib.mkIf config.file-management.yazi.file-chooser.enable { + home.file.".config/xdg-desktop-portal-termfilechooser/config" = { + source = lib.getExe config.file-management.yazi.file-chooser.package; + }; + }) ]; } diff --git a/modules/file-management/yazi/file-chooser.sh b/modules/file-management/yazi/file-chooser.sh new file mode 100644 index 0000000..7978222 --- /dev/null +++ b/modules/file-management/yazi/file-chooser.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# $1 toggles multiple selection +# $2 toggles directory select mode +# $3 toggles save file mode +# $4 is the initial directory path +# $5 is the output path file + +# multiple="$1" +directory="$2" +# save="$3" +path="$4" +out="$5" + +# Pick directory vs single/multiple file +if [ "$directory" = "1" ]; then + # Outputs the final working directory path on exit + exec yazi "$path" --cwd-file="$out" +else + # Writes all selected file paths to the output file on exit + exec yazi "$path" --chooser-file="$out" +fi diff --git a/modules/file-management/yazi/yazi-file-chooser.sh b/modules/file-management/yazi/yazi-file-chooser.sh deleted file mode 100644 index 7978222..0000000 --- a/modules/file-management/yazi/yazi-file-chooser.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# $1 toggles multiple selection -# $2 toggles directory select mode -# $3 toggles save file mode -# $4 is the initial directory path -# $5 is the output path file - -# multiple="$1" -directory="$2" -# save="$3" -path="$4" -out="$5" - -# Pick directory vs single/multiple file -if [ "$directory" = "1" ]; then - # Outputs the final working directory path on exit - exec yazi "$path" --cwd-file="$out" -else - # Writes all selected file paths to the output file on exit - exec yazi "$path" --chooser-file="$out" -fi -- cgit v1.2.3