summaryrefslogtreecommitdiffstats
path: root/lass/2configs/zsh.nix
blob: 7b0ef79f3ff7a7141c99e615b3407bf566b534a7 (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
126
127
{ config, lib, pkgs, ... }:
{
  environment.systemPackages = [ pkgs.fzf ];
  programs.zsh = {
    enable = true;
    shellInit = ''
      #disable config wizard
      zsh-newuser-install() { :; }
    '';
    interactiveShellInit = ''
      setopt autocd extendedglob
      bindkey -e

      #history magic
      bindkey "" up-line-or-local-history
      bindkey "" down-line-or-local-history

      up-line-or-local-history() {
          zle set-local-history 1
          zle up-line-or-history
          zle set-local-history 0
      }
      zle -N up-line-or-local-history
      down-line-or-local-history() {
          zle set-local-history 1
          zle down-line-or-history
          zle set-local-history 0
      }
      zle -N down-line-or-local-history

      setopt share_history
      setopt hist_ignore_dups
      # setopt inc_append_history
      bindkey '^R' history-incremental-search-backward

      #C-x C-e open line in editor
      autoload -z edit-command-line
      zle -N edit-command-line
      bindkey "^X^E" edit-command-line

      #fzf inclusion
      source ${pkgs.fzf}/share/fzf/completion.zsh
      source ${pkgs.fzf}/share/fzf/key-bindings.zsh

      #completion magic
      autoload -Uz compinit
      compinit
      zstyle ':completion:*' menu select

      #enable automatic rehashing of $PATH
      zstyle ':completion:*' rehash true

      eval $(dircolors -b ${pkgs.fetchFromGitHub {
        owner = "trapd00r";
        repo = "LS_COLORS";
        rev = "master";
        sha256="05lh5w3bgj9h8d8lrbbwbzw8788709cnzzkl8yh7m1dawkpf6nlp";
      }}/LS_COLORS)

      #beautiful colors
      alias ls='ls --color'
      # zstyle ':completion:*:default' list-colors ''${(s.:.)LS_COLORS}

      #emacs bindings
      bindkey "[7~" beginning-of-line
      bindkey "[8~" end-of-line
      bindkey "Oc" emacs-forward-word
      bindkey "Od" emacs-backward-word

      #aliases
      alias ll='ls -l'
      alias la='ls -la'

      #fancy window title magic
      case $TERM in
        (*xterm* | *rxvt*)
          function precmd {
            if test -n "$SSH_CLIENT"; then
              echo -ne "\033]0;$$ $USER@$HOST $PWD\007"
            else
              echo -ne "\033]0;$$ $USER@$PWD\007"
            fi
          }
          # This is seen while the shell waits for a command to complete.
          function preexec {
            if test -n "$SSH_CLIENT"; then
              echo -ne "\033]0;$$ $USER@$HOST $PWD $1\007"
            else
              echo -ne "\033]0;$$ $USER@$PWD $1\007"
            fi
          }
        ;;
      esac
    '';
    promptInit = ''
      # TODO: figure out why we need to set this here
      HISTSIZE=900001
      HISTFILESIZE=$HISTSIZE
      SAVEHIST=$HISTSIZE

      autoload -U promptinit
      promptinit

      error='%(?..%F{red}%?%f )'

      case $UID in
        0)
          username='%F{red}root%f '
          ;;
        1337)
          username=""
          ;;
        *)
          username='%F{blue}%n%f '
          ;;
      esac

      if test -n "$SSH_CLIENT"; then
        PROMPT="$error$username@%F{magenta}%M%f %~ "
      else
        PROMPT="$error$username%~ "
      fi
    '';
  };
  users.users.mainUser.shell = "/run/current-system/sw/bin/zsh";
  users.users.root.shell = "/run/current-system/sw/bin/zsh";
}