summary refs log tree commit diff stats
path: root/user/settings/fish.nix
blob: 480c9ade27e946c42b6215b8775da735f8e020e0 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{ pkgs
, lib
, ...
}: {
  programs.fish = {
    enable = true;
    plugins =
      let
        fromNixpkgs = pkg: { name = pkg.name; src = pkg.src; };
      in
      with pkgs.fishPlugins; [
        (fromNixpkgs fzf-fish)
        (fromNixpkgs autopair)
        {
          name = "fishplugin-hydro";
          src = pkgs.fetchFromGitHub {
            owner = "jorgebucaran";
            repo = "hydro";
            hash = "sha256-QYq4sU41/iKvDUczWLYRGqDQpVASF/+6brJJ8IxypjE=";
            rev = "9c93b89573bd722f766f2190a862ae55e728f6ba";
          };
        }
        {
          name = "ghq";
          src = pkgs.fetchFromGitHub {
            owner = "decors";
            repo = "fish-ghq";
            sha256 = "0cv7jpvdfdha4hrnjr887jv1pc6vcrxv2ahy7z6x562y7fd77gg9";
            # date = "2021-07-16T13:17:09+09:00";
            rev = "cafaaabe63c124bf0714f89ec715cfe9ece87fa2";
          };
        }
      ];
    interactiveShellInit = ''
      bind \es __ghq_repository_search
      # don't bind ctrl-t, it does nice things on macOS/BSD
      set FZF_CTRL_T_COMMAND
      set --export FZF_DEFAULT_OPTS '--cycle --layout=reverse --border --height=90% --preview-window=wrap --marker="*"'
      fzf_configure_bindings --directory=\cx\cf

      set --global hydro_multiline true
      set --global hydro_color_pwd 00AFFF
      set --global hydro_color_git 5FD700
      set --global hydro_color_start FF00FF
      set --global hydro_color_error D70000
      set --global hydro_color_prompt 5FAF00
      set --global hydro_color_duration 87875F
    '';
    shellAliases = {
      hist-freq-lines = lib.mkForce "history | sort | uniq -c | sort -gr | head -n100 | less";
      hist-freq-commands = lib.mkForce "history | cut -d' ' -f 1 | sort | uniq -c | sort -gr | head -n100 | less";
    };
    shellAbbrs = {
      "!!" = {
        position = "anywhere";
        function = "last_history_item";
      };
    };
    functions = {
      ds = "du -hd1 $argv[1] | sort -h";
      last_history_item = "echo $history[1]";
    } // (lib.attrsets.optionalAttrs pkgs.stdenv.isLinux {
      open = ''
        argparse h/help a/application -- $argv
        or return

        if set -ql _flag_help
           echo "open [-h|--help] [-a application] [arguments...]"
           return 1
        end

        if set -ql _flag_application
           # TODO: support reverse-domain- named files (e.g. org.kde.kate.desktop)
           ${pkgs.gtk3}/bin/gtk-launch $argv[1]
        else
          xdg-open $argv
        end
      '';
    });
  };
  xdg.configFile."fish/completions" = {
    recursive = true;
    source = ./fish/completions;
  };
  xdg.configFile."fish/functions" = {
    recursive = true;
    source = ./fish/functions;
  };

  programs.nix-your-shell = {
    enable = true;
  };
}