fork/home-manager
git clone https://git.julia.blue/fork/home-manager
b62f5496
master
1{ config , pkgs , lib , ...} : 2 3let 4 5inherit ( lib ) 6mkEnableOption mkPackageOption mkIf pipe fileContents splitString ; 7cfg = config . programs . carapace ; 8bin = cfg . package + "/bin/carapace" ; 9 10in { 11meta . maintainers = with lib . maintainers ; [ weathercold bobvanderlinden ]; 12 13options . programs . carapace = { 14enable = 15mkEnableOption "carapace, a multi-shell multi-command argument completer" ; 16 17package = mkPackageOption pkgs "carapace" { }; 18 19enableBashIntegration = mkEnableOption "Bash integration" // { 20default = true ; 21}; 22 23enableZshIntegration = mkEnableOption "Zsh integration" // { 24default = true ; 25}; 26 27enableFishIntegration = mkEnableOption "Fish integration" // { 28default = true ; 29}; 30 31enableNushellIntegration = mkEnableOption "Nushell integration" // { 32default = true ; 33}; 34}; 35 36config = mkIf cfg . enable { 37home . packages = [ cfg . package ]; 38 39programs = { 40bash . initExtra = mkIf cfg . enableBashIntegration '' 41source <( ${ bin } _carapace bash) 42'' ; 43 44zsh . initExtra = mkIf cfg . enableZshIntegration '' 45source <( ${ bin } _carapace zsh) 46'' ; 47 48fish . interactiveShellInit = mkIf cfg . enableFishIntegration '' 49${ bin } _carapace fish | source 50'' ; 51 52nushell = mkIf cfg . enableNushellIntegration { 53# Note, the ${"$"} below is a work-around because xgettext otherwise 54# interpret it as a Bash i18n string. 55extraEnv = '' 56let carapace_cache = " ${ config . xdg . cacheHome } /carapace" 57if not ($carapace_cache | path exists) { 58mkdir $carapace_cache 59} 60${ bin } _carapace nushell | save -f ${ "$" } "($carapace_cache)/init.nu" 61'' ; 62extraConfig = '' 63source ${ config . xdg . cacheHome } /carapace/init.nu 64'' ; 65}; 66}; 67 68xdg . configFile = 69mkIf ( config . programs . fish . enable && cfg . enableFishIntegration ) ( 70# Convert the entries from `carapace --list` to empty 71# xdg.configFile."fish/completions/NAME.fish" entries. 72# 73# This is to disable fish builtin completion for each of the 74# carapace-supported completions It is in line with the instructions from 75# carapace-bin: 76# 77# carapace --list | awk '{print $1}' | xargs -I{} touch ~/.config/fish/completions/{}.fish 78# 79# See https://github.com/rsteube/carapace-bin#getting-started 80let 81carapaceListFile = pkgs . runCommandLocal "carapace-list" { 82buildInputs = [ cfg . package ]; 83} '' 84${ bin } --list > $ out 85'' ; 86in pipe carapaceListFile [ 87fileContents 88( splitString "\n" ) 89( map ( builtins . match "^([a-z0-9-]+) .*" )) 90( builtins . filter 91( match :match != null && ( builtins . length match ) > 0 )) 92( map ( match :builtins . head match )) 93( map ( name :{ 94name = "fish/completions/ ${ name } .fish" ; 95value = { text = "" ; }; 96})) 97builtins . listToAttrs 98]); 99}; 100}