about summary refs log tree commit diff
path: root/pkgs/shells/fish
diff options
context:
space:
mode:
authorpacien <pacien.trangirard@pacien.net>2021-01-05 17:20:39 +0100
committerpacien <pacien.trangirard@pacien.net>2021-01-05 17:20:39 +0100
commitae5c6621825f73fb32a734b4bf2127655369f97a (patch)
treea917219a41aa45f58f8f28c32f74248766e76445 /pkgs/shells/fish
parenta14ea3aeccc83f2545bbce12cf47638c8b87d8c4 (diff)
downloadnixlib-ae5c6621825f73fb32a734b4bf2127655369f97a.tar
nixlib-ae5c6621825f73fb32a734b4bf2127655369f97a.tar.gz
nixlib-ae5c6621825f73fb32a734b4bf2127655369f97a.tar.bz2
nixlib-ae5c6621825f73fb32a734b4bf2127655369f97a.tar.lz
nixlib-ae5c6621825f73fb32a734b4bf2127655369f97a.tar.xz
nixlib-ae5c6621825f73fb32a734b4bf2127655369f97a.tar.zst
nixlib-ae5c6621825f73fb32a734b4bf2127655369f97a.zip
wrapFish: add fish shell wrapper package
This adds a wrapper for fish which allows creating shells pre-initialised
with some completions, functions, and configuration scripts from given paths
or from fish plugin packages (`pkgs.fishPlugins.*`).

This is especially handy when one wants to try a plugin in an ephemeral shell.

GitHub: see https://github.com/NixOS/nixpkgs/pull/107834#discussion_r550612519
Diffstat (limited to 'pkgs/shells/fish')
-rw-r--r--pkgs/shells/fish/wrapper.nix25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkgs/shells/fish/wrapper.nix b/pkgs/shells/fish/wrapper.nix
new file mode 100644
index 000000000000..053568bc6b9b
--- /dev/null
+++ b/pkgs/shells/fish/wrapper.nix
@@ -0,0 +1,25 @@
+{ lib, writeShellScriptBin, fish }:
+
+with lib;
+
+makeOverridable ({
+  completionDirs ? [],
+  functionDirs ? [],
+  confDirs ? [],
+  pluginPkgs ? []
+}:
+
+let
+  vendorDir = kind: plugin: "${plugin}/share/fish/vendor_${kind}.d";
+  complPath = completionDirs ++ map (vendorDir "completions") pluginPkgs;
+  funcPath = functionDirs ++ map (vendorDir "functions") pluginPkgs;
+  confPath = confDirs ++ map (vendorDir "conf") pluginPkgs;
+  safeConfPath = map escapeShellArg confPath;
+
+in writeShellScriptBin "fish" ''
+  ${fish}/bin/fish --init-command "
+    set --prepend fish_complete_path ${escapeShellArgs complPath}
+    set --prepend fish_function_path ${escapeShellArgs funcPath}
+    for c in {${concatStringsSep "," safeConfPath}}/*; source $c; end
+  " "$@"
+'')