Profpatsch/users/Profpatsch/nixos-modules/programs/fish-fasd.nix
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{ pkgs, config, lib, ... }:

with lib;

let cfg = config.profpatsch.programs.fish.fasd;
in

{
  options.profpatsch.programs.fish.fasd = {
    enable = mkEnableOption "fasd integration in fish";
  };

  config = mkIf cfg.enable {

    environment.systemPackages = [ pkgs.fasd ];

    programs.fish = {
      interactiveShellInit = let fasd = "${pkgs.fasd}/bin/fasd"; in ''
        function _run_fasd -e fish_preexec
          ${fasd} --proc (${fasd} --sanitize "$argv") > "/dev/null" 2>&1
        end
        function z --description "Jump to folder by usage frequency"
          cd (fasd -d -e 'printf %s' "$argv")
        end
        set PATH (dirname ${fasd}) $PATH
      '';
    };

  };
}