From c22f3e1d2932a6e12ea739750e3f057a44d00c79 Mon Sep 17 00:00:00 2001
From: Jonas Holst Damtoft <jonasdamtoft@hotmail.com>
Date: Fri, 12 Apr 2019 12:33:51 +0200
Subject: [PATCH] fish: basic completions support

---
 modules/programs/fish.nix | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix
index 5a076e2c3..8e06dda59 100644
--- a/modules/programs/fish.nix
+++ b/modules/programs/fish.nix
@@ -14,13 +14,13 @@ let
     mapAttrsToList (k: v: "alias ${k}='${v}'") cfg.shellAliases
   );
 
-  fileType = types.submodule (
+  fileType = textGen: types.submodule (
     { name, config, ... }: {
       options = {
         body = mkOption {
           default = null;
           type = types.nullOr types.lines;
-          description = "Body of the function.";
+          description = "Body of the file.";
         };
 
         source = mkOption {
@@ -36,11 +36,7 @@ let
         source = mkIf (config.body != null) (
           mkDefault (pkgs.writeTextFile {
             inherit name;
-            text = ''
-            function ${name}
-              ${config.body}
-            end
-            '';
+            text = textGen name config.body;
             executable = true;
           })
         );
@@ -125,12 +121,24 @@ in
     };
 
     programs.fish.functions = mkOption {
-      type = types.attrsOf fileType;
+      type = types.attrsOf (fileType (name: body: ''
+            function ${name}
+              ${body}
+            end
+            ''));
       default = {};
       description = ''
         Functions to add to fish.
       '';
     };
+
+    programs.fish.completions = mkOption {
+      type = types.attrsOf (fileType (name: body: body));
+      default = {};
+      description = ''
+        Completions to add to fish.
+      '';
+    };
   };
 
   config = mkIf cfg.enable (mkMerge [{