aboutsummaryrefslogtreecommitdiff
path: root/home-manager/zsh/default.nix
blob: d713873acb8210846bba80a663edfeacde24a4ac (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{ config, pkgs, lib, ... }: let
  nixosScript = ''
   nixos() {
    case $1 in
      update | up)
        if [ "$#" -gt 1 ]; then
          echo "Error: 'nixos update' takes no additional arguments."
          return 1
        fi
        nh os switch $HOME/.nix --ask
        ;;
      upgrade)
        if [ "$#" -gt 1 ]; then
          echo "Error: 'nixos upgrade' takes no additional arguments."
          return 1
        fi
        nh os switch $HOME/.nix -u --ask
        ;;
      clean)
        nh clean all --verbose
        ;;
      config)
        hx ~/.nix/"$2"
        ;;
      *)
        echo "Usage: nixos update | up || nixos upgrade || nixos config <path>"
        ;;
      esac
    }

    nix() {
      if [[ $1 == "develop" ]]; then
        shift
        local flake
        case $1 in
          python)
            flake="$HOME/.nix#python"
            shift
          ;;
          nim)
            flake="$HOME/.nix#nim"
            shift
          ;;
          js)
            flake="$HOME/.nix#js"
            shift
          ;;
          *)
            flake="$1"
            shift
          ;;
        esac
        command nix develop "$flake" -c zsh
      else
        command nix "$@"
      fi
    }

    _nixos_autocomplete() {
      _arguments \
        '1: :->subcmd' \
        '2: :->files'

      case $state in
        subcmd)
          local -a commands
          commands=("update" "config")
          _describe 'command' commands
          ;;
        files)
          # Check if the subcommand is config.
          if [[ $words[2] == "config" ]]; then
             _files -W "$HOME/.nix" -g '*'
          fi
          ;;
      esac
    }

    compdef _nixos_autocomplete nixos
  '';
in {
  programs.zsh = {
    enable = true;

    autosuggestion.enable = true;
    enableCompletion = true;
    syntaxHighlighting.enable = true;

    shellAliases = {
      ls = "eza --icons=always --color=always";
      ll = "eza -a  --long --icons=always --color=always --no-time";
      lt = "eza -a  --long --tree --icons=always --color=always --no-time";

      cat = "bat";
      mk = "(){ mkdir -p $1 && cd $1 }";

      grep = "grep --color=auto";

      mv = "mv -i";
      cp = "cp -i";
      rm = "rm -i";

      fetch = "fastfetch -c examples/7";

      nix-shell = "nix-shell --run $SHELL";
    };

    initContent = ''
      ${nixosScript};
      eval "$(atuin init zsh)"
      eval "$(starship init zsh)"
    '';
  };

  programs = {
    starship = {
      enable = true;
    };

    atuin = {
      enable = true;
      enableZshIntegration = true;
    };
  };
}
Directive (EU) 2019/790, Article 4(3); all rights regarding Text and Data Mining (TDM) are reserved.