This repository has no description
5.6 kB
192 lines
1{ ... }:
2{
3 perSystem =
4 { pkgs, ... }:
5 let
6 zshrc = ''
7 autoload -U compinit && compinit
8
9 # Setup custom interactive shell init stuff.
10 # Bind gpg-agent to this TTY if gpg commands are used.
11 export GPG_TTY=$(tty)
12
13 # show how long a command takes
14 ZSH_COMMAND_TIME_MIN_SECONDS=3
15 ZSH_COMMAND_TIME_EXCLUDE=(vim)
16 ZSH_COMMAND_TIME_MSG="took: %s sec"
17 source ${
18 pkgs.fetchFromGitHub {
19 owner = "popstas";
20 repo = "zsh-command-time";
21 rev = "803d26eef526bff1494d1a584e46a6e08d25d918";
22 hash = "sha256-ndHVFcz+XmUW0zwFq7pBXygdRKyPLjDZNmTelhd5bv8=";
23 }
24 }/command-time.plugin.zsh
25
26 unsetopt nomatch # no matches found urls
27 setopt autocd extendedglob
28 bindkey -e
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 if type -p atuin >/dev/null; then
41 export ATUIN_CONFIG_DIR=${pkgs.writeTextDir "/config.toml" ''
42 auto_sync = true
43 update_check = false
44 sync_address = "http://green.r:8888"
45 sync_frequency = 0
46 style = "compact"
47 ''};
48 export ATUIN_NOBIND="true" # disable all keybdinings of atuin
49 eval "$(${pkgs.atuin}/bin/atuin init zsh)" # TODO make this optional?
50 bindkey '^r' _atuin_search_widget # bind ctrl+r to atuin
51 # use zsh only session history
52 fc -p
53 fi
54
55 #completion magic
56 autoload -Uz compinit
57 compinit
58 zstyle ':completion:*' menu select
59
60 #enable automatic rehashing of $PATH
61 zstyle ':completion:*' rehash true
62
63 # fancy mv which interactively gets the second argument if not given
64 function mv() {
65 if [[ "$#" -ne 1 ]] || [[ ! -e "$1" ]]; then
66 command mv -v "$@"
67 return
68 fi
69
70 newfilename="$1"
71 vared newfilename
72 command mv -v -- "$1" "$newfilename"
73 }
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 # This function is called whenever a command is not found.
85 command_not_found_handler() {
86 local p='${pkgs.nix-index}/etc/profile.d/command-not-found.sh'
87 if [ -x "$p" ] && [ -f '/nix/var/nix/profiles/per-user/root/channels/nixos/programs.sqlite' ]; then
88 # Run the helper program.
89 "$p" "$@"
90
91 # Retry the command if we just installed it.
92 if [ $? = 126 ]; then
93 "$@"
94 else
95 return 127
96 fi
97 else
98 # Indicate than there was an error so ZSH falls back to its default handler
99 echo "$1: command not found" >&2
100 return 127
101 fi
102 }
103
104
105 # Setup aliases.
106 alias -- grep='grep --color=auto'
107 alias -- ip='ip -color=auto'
108 alias -- l='ls -alh'
109 alias -- la='ls -la'
110 alias -- ll='ls -l'
111 alias -- ls='ls --color'
112 alias -- ns='nix-shell --command zsh'
113
114 # Setup prompt.
115 autoload -U promptinit
116 promptinit
117
118 p_error='%(?..%F{red}%?%f )'
119 t_error='%(?..%? )'
120
121 case $UID in
122 0)
123 p_username='%F{red}root%f'
124 t_username='root'
125 ;;
126 1337)
127 p_username=""
128 t_username=""
129 ;;
130 *)
131 p_username='%F{blue}%n%f'
132 t_username='%n'
133 ;;
134 esac
135
136 if test -n "$SSH_CLIENT"; then
137 p_hostname='@%F{magenta}%M%f '
138 t_hostname='@%M '
139 else
140 p_hostname=""
141 t_hostname=""
142 fi
143
144 #check if in nix shell
145 if test -n "$IN_NIX_SHELL"; then
146 p_nixshell='%F{green}[s]%f '
147 t_nixshell='[s] '
148 else
149 p_nixshell=""
150 t_nixshell=""
151 fi
152
153 PROMPT="$p_error$p_username$p_hostname$p_nixshell%~ "
154 TITLE="$t_error$t_username$t_hostname$t_nixshell%~"
155 case $TERM in
156 (*xterm* | *rxvt*)
157 function precmd {
158 PROMPT_EVALED=$(print -P "$TITLE")
159 echo -ne "\033]0;$$ $PROMPT_EVALED\007"
160 }
161 # This seems broken for some reason
162 # # This is seen while the shell waits for a command to complete.
163 # function preexec {
164 # PROMPT_EVALED=$(print -P "$TITLE")
165 # echo -ne "\033]0;$$ $PROMPT_EVALED $1\007"
166 # }
167 ;;
168 esac
169
170
171 # Disable some features to support TRAMP.
172 if [ "$TERM" = dumb ]; then
173 unsetopt zle prompt_cr prompt_subst
174 unset RPS1 RPROMPT
175 PS1='$ '
176 PROMPT='$ '
177 fi
178 '';
179 in
180 {
181 packages.shell = pkgs.writeScriptBin "shell" ''
182 #!/bin/sh
183 export ZDOTDIR=${pkgs.writeTextDir "/.zshrc" zshrc}
184 exec ${pkgs.zsh}/bin/zsh "$@"
185 '';
186 packages.zsh = pkgs.writeScriptBin "zsh" ''
187 #!/bin/sh
188 export ZDOTDIR=${pkgs.writeTextDir "/.zshrc" zshrc}
189 exec ${pkgs.zsh}/bin/zsh "$@"
190 '';
191 };
192}