aboutsummaryrefslogtreecommitdiffstats
path: root/oni/home/services/zsh.scm
blob: 09d248f696c8ef5fa21e0727ca7e0dfaeb62440c (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
(define-module (oni home services zsh)
  #:use-module (ice-9 string-fun)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages shellutils)
  #:use-module (gnu home services)
  #:use-module (gnu home services shells)
  #:use-module (gnu home services utils)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module ((oni packages atuin)
                #:select (rust-atuin-18))
  #:use-module (oni packages zsh)

  #:export (home-zsh-autosuggestions-service-type
            home-zsh-autosuggestions-configuration
            home-zsh-syntax-highlighting-service-type
            home-zsh-syntax-highlighting-configuration
            home-zsh-contextual-abbrevs-service-type
            home-zsh-contextual-abbrevs-configuration
            home-zsh-autopair-service-type
            home-zsh-autopair-configuration
            home-zsh-atuin-service-type
            home-zsh-atuin-configuration))

(define-configuration/no-serialization home-zsh-autosuggestions-configuration
  (package
   (package zsh-autosuggestions)
   "Package to use for setting zsh-autosuggestions"))

(define (add-zsh-autosuggestions config)
  (home-zsh-extension
   (zshrc
    (list
     (mixed-text-file
      "zshrc"
      "source " (home-zsh-autosuggestions-configuration-package config) "/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh")))))

(define (add-zsh-autosuggestions-packages config)
  (list (home-zsh-autosuggestions-configuration-package config)))

(define home-zsh-autosuggestions-service-type
  (service-type
   (name 'home-zsh-autosuggestions)
   (extensions
    (list (service-extension
           home-zsh-service-type
           add-zsh-autosuggestions)
          (service-extension
           home-profile-service-type
           add-zsh-autosuggestions-packages)))
   (compose identity)
   (default-value (home-zsh-autosuggestions-configuration))
   (description "Install and configure zsh-autosuggestions.")))


(define-configuration/no-serialization home-zsh-syntax-highlighting-configuration
  (package
   (package zsh-syntax-highlighting)
   "Package to use for setting zsh-syntax-highlighting."))

(define (add-zsh-syntax-highlighting config)
  (home-zsh-extension
   (zshrc
    (list
     (mixed-text-file
      "zshrc"
      "source " (home-zsh-syntax-highlighting-configuration-package config) "/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh")))))

(define (add-zsh-syntax-highlighting-packages config)
  (list (home-zsh-syntax-highlighting-configuration-package config)))

(define home-zsh-syntax-highlighting-service-type
  (service-type
   (name 'home-zsh-syntax-highlighting)
   (extensions
    (list (service-extension
           home-zsh-service-type
           add-zsh-syntax-highlighting)
          (service-extension
           home-profile-service-type
           add-zsh-syntax-highlighting-packages)))
   (compose identity)
   (default-value (home-zsh-syntax-highlighting-configuration))
   (description "Install and configure zsh-syntax-highlighting.")))

(define-configuration/no-serialization home-zsh-contextual-abbrevs-configuration
  (package
    (package zsh-contextual-abbrevs)
    "Package to use for setting zsh-contexual-abbrevs."))

(define (add-zsh-contextual-abbrevs config)
  (home-zsh-extension
   (zshrc
    (list
     (mixed-text-file
      "zshrc"
      "source " (home-zsh-contextual-abbrevs-configuration-package config) "/share/zsh/plugins/zsh-contextual-abbrevs/contextual-abbrevs.zsh")))))

(define (add-zsh-contextual-abbrevs-packages config)
  (list (home-zsh-contextual-abbrevs-configuration-package config)))

(define home-zsh-contextual-abbrevs-service-type
  (service-type
   (name 'home-zsh-contextual-abbrevs)
   (extensions
    (list (service-extension
           home-zsh-service-type
           add-zsh-contextual-abbrevs)
          (service-extension
           home-profile-service-type
           add-zsh-contextual-abbrevs-packages)))
   (compose identity)
   (default-value (home-zsh-contextual-abbrevs-configuration))
   (description "Install and configure zsh-contextual-abbrevs.")))

(define-configuration/no-serialization home-zsh-autopair-configuration
  (package
    (package zsh-autopair)
    "Package to use for setting zsh-autopair."))

(define (add-zsh-autopair config)
  (home-zsh-extension
   (zshrc
    (list
     (mixed-text-file
      "zshrc"
      "source " (home-zsh-autopair-configuration-package config) "/share/zsh/plugins/zsh-autopair/zsh-autopair.zsh")))))

(define (add-zsh-autopair-packages config)
  (list (home-zsh-autopair-configuration-package config)))

(define home-zsh-autopair-service-type
  (service-type
   (name 'home-zsh-autopair)
   (extensions
    (list (service-extension
           home-zsh-service-type
           add-zsh-autopair)
          (service-extension
           home-profile-service-type
           add-zsh-autopair-packages)))
   (compose identity)
   (default-value (home-zsh-autopair-configuration))
   (description "Install and configure zsh-autopair.")))

(define (serialize-field-name field)
  (string-replace-substring (symbol->string field) "-" "_"))

(define (serialize-integer field value)
  (format #f "~a = ~a~%" (serialize-field-name field) value))

(define (serialize-filter-mode field value)
  (format #f "~a = ~s~%" (serialize-field-name field) (symbol->string value)))

(define (serialize-list-of-strings field value)
  (format #f "~a = ~a~%" (serialize-field-name field)
          (string-append "[" (string-join (map (λ (v) (format #f "~s" v)) value) ",") "]")))

(define (serialize-boolean field value)
  (format #f "~a = ~a~%" (serialize-field-name field) (if value "true" "false")))

(define (serialize-string field value)
  (format #f "~a = ~s~%" (serialize-field-name field) value))

(define (filter-mode? value)
  (memq value '(global host session directory workspace)))

(define-configuration home-zsh-atuin-configuration
  (package
    (package rust-atuin-18)
    "Package to use for setting atuin.")
  (inline-height
   (integer 40)
   "Set the maximum number of lines Atuin’s interface should take up.")
  (filter-mode
   (filter-mode 'global)
   "The default filter to use when searching")
  (history-filter
   (list-of-strings '())
   "The history filter allows you to exclude commands from history tracking - maybe
you want to keep ALL of your curl commands totally out of your shell history, or
maybe just some matching a pattern.")
  (enter-accept
   (boolean #f)
   "When set to true, Atuin will default to immediately executing a command rather
than the user having to press enter twice. Pressing tab will return to the shell
and give the user a chance to edit.")
  (common-subcommands
   (list-of-strings '())
   "Configures commands where we should consider the subcommand as part of the
statistics. For example, consider kubectl get rather than just kubectl.")
  (sync-address
   (string "")
   "The address of the server to sync with!"))

(define (add-zsh-atuin config)
  (home-zsh-extension
   (zshrc
    (list
     (mixed-text-file
      "zshrc"
      "eval \"$(" (home-zsh-atuin-configuration-package config) "/bin/atuin init zsh)\"\n"
      "bindkey -M emacs '^p' atuin-up-search\n"
      "bindkey -M emacs '^[p' atuin-up-search\n")))))

(define (add-zsh-atuin-configuration config)
  `(("atuin/config.toml"
     ,(mixed-text-file
       "config.toml"
       (serialize-configuration config home-zsh-atuin-configuration-fields)))))

(define (add-zsh-atuin-packages config)
  (list (home-zsh-atuin-configuration-package config)))

(define home-zsh-atuin-service-type
  (service-type
   (name 'home-zsh-atuin)
   (extensions
    (list (service-extension
           home-zsh-service-type
           add-zsh-atuin)
          (service-extension
           home-profile-service-type
           add-zsh-atuin-packages)
          (service-extension
           home-xdg-configuration-files-service-type
           add-zsh-atuin-configuration)))
   (compose identity)
   (default-value (home-zsh-atuin-configuration))
   (description "Install and configure atuin.")))