summaryrefslogtreecommitdiff
path: root/features/user/cli/shells/nushell/default.nix
blob: 71d9a96c2f5e1f41c14a0dc0bc16477782d6a966 (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
94
95
96
97
98
99
100
{
  config,
  pkgs,
  lib,
  ...
}: let
  cfg = config.features.cli.shells.nushell;
in {
  options.features.cli.shells.nushell.enable = lib.mkEnableOption "nushell";
  config = lib.mkIf cfg.enable {
    home.packages = with pkgs; [
      television
      gitprompt-rs
    ];
    programs.nushell = {
      enable = true;
      plugins = with pkgs.nushellPlugins; [
        gstat
      ];
      shellAliases = {
        "nix-shell" = "nix-shell --command 'SHELL=nu nu'";
        "cd" = "z";
        "ze" = "zellij";
        "lg" = "lazygit";
        "bk" = "cd $env.OLDPWD";
        "fg" = "job unfreeze";
      };
      configFile.text =
        /*
        nu
        */
        ''
          # Source modularized configs.
          source ${./prompt.nu}
          source ${./completion.nu}

          # General Config
          $env.config = {
            show_banner: false
            edit_mode: 'vi'

            history: {
              isolation: true # Isolate the history of each nushell session
              file_format: sqlite # Required for isolation
            }
          }
          $env.editor = "hx"

          # go should use a hidden directory
          $env.gopath = "${config.home.homeDirectory}/.go"

          # Use direnv if present.
          { ||
            if (which direnv | is-empty) {
              return
            }
            direnv export json | from json | default {} | load-env

          }

          # define a function to initialize a direnv project
          def projinit [path?: string] {
            mut path = $path
            if ($path == null) {
              $path = "./"
            }
            let path = $path | path expand
            cp -r ${./direnv-project-template}/* $path
            chmod +w $"($path)/*"
            direnv allow
          }

          # Quickly create a nix shell.
          def qs [...pkgs] {
            if $pkgs == [] {
              print "Please use a package name."
              return
            }
            let pkgs_string = $pkgs
              | each {|pkg| return $"nixpkgs#($pkg) "}
              | str join
              | str trim
            nu -c $"nix shell ($pkgs_string)"
          }

          # Quickly run a nix package.
          def qr [pkg: string] {
            nix run $"nixpkgs#($pkg)"
          }
        '';
    };
    programs.zoxide.enable = true;
    programs.carapace.enable = true;
    programs.direnv = {
      enable = true;
      nix-direnv.enable = true;
      silent = true;
    };
  };
}