{ config, lib, pkgs, ... }:
{
options.tagdex = {
enable = lib.mkEnableOption "tagdex";
wrapper = {
directory = lib.mkOption {
default = null;
description = "The directory of the music library to use.";
type = with lib.types; uniq (nullOr str);
};
enable = lib.mkEnableOption "mpv wrapper for immediate playback";
};
};
config = let
cfg = config.tagdex;
inherit (lib) mkIf optional optionalString;
in {
environment.systemPackages = optional cfg.enable pkgs.tagdex;
nixpkgs.overlays =
[ (_: _: { tagdex = pkgs.callPackage ./default.nix { }; }) ];
programs.bash.interactiveShellInit = mkIf cfg.wrapper.enable (let
pathArg = optionalString (cfg.wrapper.directory != null)
"--path ${cfg.wrapper.directory}";
in ''
td() {
${pkgs.tagdex}/bin/tagdex ${pathArg} "$@" --null | xargs --null --no-run-if-empty ${pkgs.mpv}/bin/mpv --video=no --display-tags-clr
}
source "${pkgs.tagdex}/share/bash-completion/completions/tagdex.bash"
complete -F _tagdex -o nosort -o bashdefault -o default td
'');
};
}