translate-shell: add module (#3659)

This commit is contained in:
Mario Rodas 2023-05-11 04:21:18 -05:00 committed by GitHub
parent b365342adb
commit fa720861b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 0 deletions

3
.github/CODEOWNERS vendored
View file

@ -350,6 +350,9 @@ Makefile @thiagokokada
/modules/programs/topgrade.nix @msfjarvis /modules/programs/topgrade.nix @msfjarvis
/tests/modules/programs/topgrade @msfjarvis /tests/modules/programs/topgrade @msfjarvis
/modules/programs/translate-shell.nix @marsam
/tests/modules/programs/translate-shell @marsam
/modules/programs/vim-vint.nix @tomodachi94 /modules/programs/vim-vint.nix @tomodachi94
/tests/modules/programs/vim-vint @tomodachi94 /tests/modules/programs/vim-vint @tomodachi94

View file

@ -188,6 +188,7 @@ let
./programs/tmate.nix ./programs/tmate.nix
./programs/tmux.nix ./programs/tmux.nix
./programs/topgrade.nix ./programs/topgrade.nix
./programs/translate-shell.nix
./programs/urxvt.nix ./programs/urxvt.nix
./programs/vim.nix ./programs/vim.nix
./programs/vim-vint.nix ./programs/vim-vint.nix

View file

@ -0,0 +1,52 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.translate-shell;
mkKeyValue = key: value:
let
formatValue = v:
if isBool v then
(if v then "true" else "false")
else if isString v then
''"${v}"''
else if isList v then
"[ ${concatStringsSep " " (map formatValue v)} ]"
else
toString v;
in ":${key} ${formatValue value}";
toKeyValue = generators.toKeyValue { inherit mkKeyValue; };
in {
meta.maintainers = [ maintainers.marsam ];
options.programs.translate-shell = {
enable = mkEnableOption "translate-shell";
settings = mkOption {
type = with types; attrsOf (oneOf [ bool str (listOf str) ]);
default = { };
example = {
verbose = true;
hl = "en";
tl = [ "es" "fr" ];
};
description = ''
Options to add to <filename>$XDG_CONFIG_HOME/translate-shell/init.trans</filename> file.
See <link xlink:href="https://github.com/soimort/translate-shell/wiki/Configuration"/>
for options.
'';
};
};
config = mkIf cfg.enable {
home.packages = [ pkgs.translate-shell ];
xdg.configFile."translate-shell/init.trans" =
mkIf (cfg.settings != { }) { text = "{${toKeyValue cfg.settings}}"; };
};
}

View file

@ -128,6 +128,7 @@ import nmt {
./modules/programs/tmate ./modules/programs/tmate
./modules/programs/tmux ./modules/programs/tmux
./modules/programs/topgrade ./modules/programs/topgrade
./modules/programs/translate-shell
./modules/programs/vim-vint ./modules/programs/vim-vint
./modules/programs/vscode ./modules/programs/vscode
./modules/programs/watson ./modules/programs/watson

View file

@ -0,0 +1 @@
{ translate-shell = ./translate-shell.nix; }

View file

@ -0,0 +1,27 @@
{ ... }:
{
programs.translate-shell = {
enable = true;
settings = {
verbose = true;
engine = "bing";
play = true;
hl = "en";
tl = [ "de" "fr" ];
};
};
test.stubs.translate-shell = { };
nmt.script = ''
assertFileContent home-files/.config/translate-shell/init.trans \
${builtins.toFile "translate-shell-expected-settings.trans" ''
{:engine "bing"
:hl "en"
:play true
:tl [ "de" "fr" ]
:verbose true
}''}
'';
}