This repository has no description
3.8 kB
144 lines
1{ config, lib, pkgs, ... }:
2{
3 environment.systemPackages = with pkgs; [
4 atuin
5 direnv
6 fzf
7 ];
8 environment.variables.ATUIN_CONFIG_DIR = toString (pkgs.writeTextDir "/config.toml" ''
9 auto_sync = true
10 update_check = false
11 sync_address = "http://green.r:8888"
12 sync_frequency = 0
13 style = "compact"
14 '');
15 programs.zsh = {
16 enable = true;
17 shellInit = ''
18 #disable config wizard
19 zsh-newuser-install() { :; }
20 '';
21 interactiveShellInit = ''
22 unsetopt nomatch # no matches found urls
23 setopt autocd extendedglob
24 bindkey -e
25
26
27 # # setopt inc_append_history
28 # bindkey '^R' history-incremental-search-backward
29
30 #C-x C-e open line in editor
31 autoload -z edit-command-line
32 zle -N edit-command-line
33 bindkey "^X^E" edit-command-line
34
35 #fzf inclusion
36 source ${pkgs.fzf}/share/fzf/completion.zsh
37 source ${pkgs.fzf}/share/fzf/key-bindings.zsh
38
39 # atuin distributed shell history
40 export ATUIN_NOBIND="true" # disable all keybdinings of atuin
41 eval "$(atuin init zsh)"
42 bindkey '^r' _atuin_search_widget # bind ctrl+r to atuin
43 # use zsh only session history
44 fc -p
45
46 #completion magic
47 autoload -Uz compinit
48 compinit
49 zstyle ':completion:*' menu select
50
51 #enable automatic rehashing of $PATH
52 zstyle ':completion:*' rehash true
53
54 # fancy mv which interactively gets the second argument if not given
55 function mv() {
56 if [[ "$#" -ne 1 ]] || [[ ! -e "$1" ]]; then
57 command mv -v "$@"
58 return
59 fi
60
61 newfilename="$1"
62 vared newfilename
63 command mv -v -- "$1" "$newfilename"
64 }
65
66 #beautiful colors
67 eval $(dircolors -b ${pkgs.fetchFromGitHub {
68 owner = "trapd00r";
69 repo = "LS_COLORS";
70 rev = "a75fca8545f91abb8a5f802981033ef54bf1eac0";
71 sha256="1lzj0qnj89mzh76ha137mnz2hf86k278rh0y9x124ghxj9yqsnb4";
72 }}/LS_COLORS)
73 zstyle ':completion:*:default' list-colors ''${(s.:.)LS_COLORS}
74
75 #emacs bindings
76 bindkey "[7~" beginning-of-line
77 bindkey "[8~" end-of-line
78 bindkey "Oc" emacs-forward-word
79 bindkey "Od" emacs-backward-word
80
81 # direnv integration
82 eval "$(${pkgs.direnv}/bin/direnv hook zsh)"
83 '';
84 promptInit = ''
85 autoload -U promptinit
86 promptinit
87
88 p_error='%(?..%F{red}%?%f )'
89 t_error='%(?..%? )'
90
91 case $UID in
92 0)
93 p_username='%F{red}root%f'
94 t_username='root'
95 ;;
96 1337)
97 p_username=""
98 t_username=""
99 ;;
100 *)
101 p_username='%F{blue}%n%f'
102 t_username='%n'
103 ;;
104 esac
105
106 if test -n "$SSH_CLIENT"; then
107 p_hostname='@%F{magenta}%M%f '
108 t_hostname='@%M '
109 else
110 p_hostname=""
111 t_hostname=""
112 fi
113
114 #check if in nix shell
115 if test -n "$IN_NIX_SHELL"; then
116 p_nixshell='%F{green}[s]%f '
117 t_nixshell='[s] '
118 else
119 p_nixshell=""
120 t_nixshell=""
121 fi
122
123 PROMPT="$p_error$p_username$p_hostname$p_nixshell%~ "
124 TITLE="$t_error$t_username$t_hostname$t_nixshell%~"
125 case $TERM in
126 (*xterm* | *rxvt*)
127 function precmd {
128 PROMPT_EVALED=$(print -P "$TITLE")
129 echo -ne "\033]0;$$ $PROMPT_EVALED\007"
130 }
131 # This seems broken for some reason
132 # # This is seen while the shell waits for a command to complete.
133 # function preexec {
134 # PROMPT_EVALED=$(print -P "$TITLE")
135 # echo -ne "\033]0;$$ $PROMPT_EVALED $1\007"
136 # }
137 ;;
138 esac
139 '';
140 };
141 environment.shellAliases.ns = "nix-shell --command zsh";
142
143 users.defaultUserShell = "/run/current-system/sw/bin/zsh";
144}