mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
carapace: build-time nushell config generation
This commit is contained in:
parent
3722855a1c
commit
dde05a0b10
2 changed files with 22 additions and 32 deletions
|
|
@ -1,20 +1,16 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
inherit (lib)
|
|
||||||
mkEnableOption mkPackageOption mkIf pipe fileContents splitString;
|
|
||||||
cfg = config.programs.carapace;
|
cfg = config.programs.carapace;
|
||||||
bin = cfg.package + "/bin/carapace";
|
bin = lib.getExe cfg.package;
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta.maintainers = with lib.maintainers; [ weathercold bobvanderlinden ];
|
meta.maintainers = with lib.maintainers; [ weathercold bobvanderlinden ];
|
||||||
|
|
||||||
options.programs.carapace = {
|
options.programs.carapace = {
|
||||||
enable =
|
enable = lib.mkEnableOption
|
||||||
mkEnableOption "carapace, a multi-shell multi-command argument completer";
|
"carapace, a multi-shell multi-command argument completer";
|
||||||
|
|
||||||
package = mkPackageOption pkgs "carapace" { };
|
package = lib.mkPackageOption pkgs "carapace" { };
|
||||||
|
|
||||||
enableBashIntegration =
|
enableBashIntegration =
|
||||||
lib.hm.shell.mkBashIntegrationOption { inherit config; };
|
lib.hm.shell.mkBashIntegrationOption { inherit config; };
|
||||||
|
|
@ -29,39 +25,34 @@ in {
|
||||||
lib.hm.shell.mkZshIntegrationOption { inherit config; };
|
lib.hm.shell.mkZshIntegrationOption { inherit config; };
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
home.packages = [ cfg.package ];
|
home.packages = [ cfg.package ];
|
||||||
|
|
||||||
programs = {
|
programs = {
|
||||||
bash.initExtra = mkIf cfg.enableBashIntegration ''
|
bash.initExtra = lib.mkIf cfg.enableBashIntegration ''
|
||||||
source <(${bin} _carapace bash)
|
source <(${bin} _carapace bash)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
zsh.initContent = mkIf cfg.enableZshIntegration ''
|
zsh.initContent = lib.mkIf cfg.enableZshIntegration ''
|
||||||
source <(${bin} _carapace zsh)
|
source <(${bin} _carapace zsh)
|
||||||
'';
|
'';
|
||||||
|
|
||||||
fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
|
fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
|
||||||
${bin} _carapace fish | source
|
${bin} _carapace fish | source
|
||||||
'';
|
'';
|
||||||
|
|
||||||
nushell = mkIf cfg.enableNushellIntegration {
|
nushell = lib.mkIf cfg.enableNushellIntegration {
|
||||||
# Note, the ${"$"} below is a work-around because xgettext otherwise
|
|
||||||
# interpret it as a Bash i18n string.
|
|
||||||
extraEnv = ''
|
|
||||||
let carapace_cache = "${config.xdg.cacheHome}/carapace"
|
|
||||||
if not ($carapace_cache | path exists) {
|
|
||||||
mkdir $carapace_cache
|
|
||||||
}
|
|
||||||
${bin} _carapace nushell | save -f ${"$"}"($carapace_cache)/init.nu"
|
|
||||||
'';
|
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
source ${config.xdg.cacheHome}/carapace/init.nu
|
source ${
|
||||||
|
pkgs.runCommand "carapace-nushell-config" { } ''
|
||||||
|
${bin} _carapace nushell >> "$out"
|
||||||
|
''
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
xdg.configFile = mkIf (config.programs.fish.enable
|
xdg.configFile = lib.mkIf (config.programs.fish.enable
|
||||||
&& cfg.enableFishIntegration
|
&& cfg.enableFishIntegration
|
||||||
&& lib.versionOlder config.programs.fish.package.version "4.0.0") (
|
&& lib.versionOlder config.programs.fish.package.version "4.0.0") (
|
||||||
# Convert the entries from `carapace --list` to empty
|
# Convert the entries from `carapace --list` to empty
|
||||||
|
|
@ -84,9 +75,9 @@ in {
|
||||||
} ''
|
} ''
|
||||||
${bin} --list > $out
|
${bin} --list > $out
|
||||||
'';
|
'';
|
||||||
in pipe carapaceListFile [
|
in lib.pipe carapaceListFile [
|
||||||
fileContents
|
lib.fileContents
|
||||||
(splitString "\n")
|
(lib.splitString "\n")
|
||||||
(map (builtins.match "^([a-z0-9-]+) .*"))
|
(map (builtins.match "^([a-z0-9-]+) .*"))
|
||||||
(builtins.filter
|
(builtins.filter
|
||||||
(match: match != null && (builtins.length match) > 0))
|
(match: match != null && (builtins.length match) > 0))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
{ pkgs, config, ... }:
|
{ lib, pkgs, realPkgs, config, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
programs = {
|
programs = {
|
||||||
|
|
@ -6,17 +6,16 @@
|
||||||
nushell.enable = true;
|
nushell.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_module.args.pkgs = lib.mkForce realPkgs;
|
||||||
|
|
||||||
nmt.script = let
|
nmt.script = let
|
||||||
configDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then
|
configDir = if pkgs.stdenv.isDarwin && !config.xdg.enable then
|
||||||
"home-files/Library/Application Support/nushell"
|
"home-files/Library/Application Support/nushell"
|
||||||
else
|
else
|
||||||
"home-files/.config/nushell";
|
"home-files/.config/nushell";
|
||||||
in ''
|
in ''
|
||||||
assertFileExists "${configDir}/env.nu"
|
|
||||||
assertFileRegex "${configDir}/env.nu" \
|
|
||||||
'/nix/store/.*carapace.*/bin/carapace _carapace nushell \| save -f \$"(\$carapace_cache)/init\.nu"'
|
|
||||||
assertFileExists "${configDir}/config.nu"
|
assertFileExists "${configDir}/config.nu"
|
||||||
assertFileRegex "${configDir}/config.nu" \
|
assertFileRegex "${configDir}/config.nu" \
|
||||||
'source /.*/\.cache/carapace/init\.nu'
|
'source /nix/store/[^/]*-carapace-nushell-config'
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue