From 223b9deeaddb9b8e2a6325fb661d2f62abe8450d Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Mon, 28 Mar 2022 11:19:38 -0400 Subject: [PATCH] pistol: add module --- .github/CODEOWNERS | 3 ++ modules/lib/maintainers.nix | 6 +++ modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/programs/pistol.nix | 49 +++++++++++++++++++++++ tests/default.nix | 1 + tests/modules/programs/pistol/config.nix | 31 ++++++++++++++ tests/modules/programs/pistol/default.nix | 1 + 8 files changed, 99 insertions(+) create mode 100644 modules/programs/pistol.nix create mode 100644 tests/modules/programs/pistol/config.nix create mode 100644 tests/modules/programs/pistol/default.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 96015153b..30b4f4730 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -211,6 +211,9 @@ /modules/programs/pidgin.nix @rycee +/modules/programs/pistol.nix @mtoohey31 +/tests/modules/programs/pistol @mtoohey31 + /modules/programs/piston-cli.nix @ethancedwards8 /modules/programs/powerline-go.nix @DamienCassou diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index fec5c0342..c4507021c 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -287,4 +287,10 @@ fingerprint = "D5D6 FD1F 0D9A 3284 FB9B C26D 3F98 EC7E C2B8 7ED1"; }]; }; + mtoohey = { + name = "Matthew Toohey"; + email = "contact@mtoohey.com"; + github = "mtoohey31"; + githubId = 36740602; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index fd8ca1bc8..a1e4db3aa 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -568,6 +568,13 @@ in A new module is available: 'programs.micro'. ''; } + + { + time = "2022-06-24T22:40:27+00:00"; + message = '' + A new module is available: 'programs.pistol'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 363e127bf..5546825ae 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -132,6 +132,7 @@ let ./programs/pazi.nix ./programs/pet.nix ./programs/pidgin.nix + ./programs/pistol.nix ./programs/piston-cli.nix ./programs/powerline-go.nix ./programs/pubs.nix diff --git a/modules/programs/pistol.nix b/modules/programs/pistol.nix new file mode 100644 index 000000000..8d5d6d71c --- /dev/null +++ b/modules/programs/pistol.nix @@ -0,0 +1,49 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.pistol; + + configFile = + concatStringsSep "\n" (mapAttrsToList (k: v: "${k} ${v}") cfg.config); + +in { + meta.maintainers = [ hm.maintainers.mtoohey ]; + + options.programs.pistol = { + enable = mkEnableOption '' + Pistol, a general purpose file previewer designed for terminal file + managers''; + + config = mkOption { + type = with types; attrsOf str; + default = { }; + example = literalExpression '' + { + "text/*" = "bat --paging=never --color=always %pistol-filename%"; + "inode/directory" = "ls -l --color %pistol-filename%"; + } + ''; + description = '' + Pistol configuration written to + $XDG_CONFIG_HOME/pistol/pistol.conf. + ''; + }; + + }; + + config = mkIf cfg.enable (mkMerge [ + { home.packages = [ pkgs.pistol ]; } + + (mkIf (cfg.config != { } && pkgs.stdenv.hostPlatform.isDarwin) { + home.file."Library/Application Support/pistol/pistol.conf".text = + configFile; + }) + + (mkIf (cfg.config != { } && !pkgs.stdenv.hostPlatform.isDarwin) { + xdg.configFile."pistol/pistol.conf".text = configFile; + }) + ]); +} diff --git a/tests/default.nix b/tests/default.nix index 3c6cc6543..97ec5567c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -88,6 +88,7 @@ import nmt { ./modules/programs/nushell ./modules/programs/pandoc ./modules/programs/pet + ./modules/programs/pistol ./modules/programs/powerline-go ./modules/programs/pubs ./modules/programs/qutebrowser diff --git a/tests/modules/programs/pistol/config.nix b/tests/modules/programs/pistol/config.nix new file mode 100644 index 000000000..324304d3c --- /dev/null +++ b/tests/modules/programs/pistol/config.nix @@ -0,0 +1,31 @@ +{ pkgs, ... }: + +let + + expected = builtins.toFile "settings-expected" '' + application/json bat --paging=never --color=always --style=auto --wrap=character --terminal-width=%pistol-extra0% --line-range=1:%pistol-extra1% %pistol-filename% + text/* bat --paging=never --color=always --style=auto --wrap=character --terminal-width=%pistol-extra0% --line-range=1:%pistol-extra1% %pistol-filename%''; + +in { + programs.pistol = { + enable = true; + config = { + "text/*" = + "bat --paging=never --color=always --style=auto --wrap=character --terminal-width=%pistol-extra0% --line-range=1:%pistol-extra1% %pistol-filename%"; + "application/json" = + "bat --paging=never --color=always --style=auto --wrap=character --terminal-width=%pistol-extra0% --line-range=1:%pistol-extra1% %pistol-filename%"; + }; + }; + + test.stubs.pistol = { }; + + nmt.script = let + path = if pkgs.stdenv.hostPlatform.isDarwin then + "home-files/Library/Application Support/pistol/pistol.conf" + else + "home-files/.config/pistol/pistol.conf"; + in '' + assertFileExists '${path}' + assertFileContent '${path}' '${expected}' + ''; +} diff --git a/tests/modules/programs/pistol/default.nix b/tests/modules/programs/pistol/default.nix new file mode 100644 index 000000000..ac147c378 --- /dev/null +++ b/tests/modules/programs/pistol/default.nix @@ -0,0 +1 @@ +{ pistol-config = ./config.nix; }