~abcdw/rde

rde/rde/features/shells.scm -rw-r--r-- 4.4 KiB
e98d6a8eAndrew Tropin rde: gnupg: Add copyright preamble. 19 hours ago
                                                                                
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
;;; rde --- Reproducible development environment.
;;;
;;; Copyright © 2021, 2022 Andrew Tropin <andrew@trop.in>
;;;
;;; This file is part of rde.
;;;
;;; rde is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; rde is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with rde.  If not, see <http://www.gnu.org/licenses/>.

(define-module (rde features shells)
  #:use-module (rde packages)
  #:use-module (rde features)
  #:use-module (rde features predicates)
  #:use-module (gnu home services)
  #:use-module (rde home services shells)
  #:use-module (rde home services shellutils)
  #:use-module (gnu services)
  #:use-module (gnu packages shells)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages shellutils)
  #:use-module (guix gexp)
  #:use-module (rde gexp)

  #:export (feature-zsh
            feature-bash))

(define* (feature-zsh
          #:key
          (zsh zsh)
          (zsh-autosuggestions zsh-autosuggestions)
          (rde-defaults? #t)
          (zshrc '())
          (zprofile '())
          (zshenv '())
          (zlogout '())
          (default-shell? #t)
          (enable-zsh-autosuggestions? #t))
  "Configure Zsh."
  (ensure-pred file-like? zsh)
  (ensure-pred file-like? zsh-autosuggestions)
  (ensure-pred boolean? default-shell?)
  (ensure-pred boolean? enable-zsh-autosuggestions?)
  (ensure-pred boolean? rde-defaults?)

  (define (zsh-home-services config)
    "Returns home services related to Zsh."
    (list
     (when default-shell?
       (simple-service
        'set-default-shell-to-zsh
        home-environment-variables-service-type
        `(("SHELL" . ,(file-append zsh "/bin/zsh")))))

     (when enable-zsh-autosuggestions?
       (service home-zsh-autosuggestions-service-type
                zsh-autosuggestions))

     (when (get-value 'wayland config)
       (let* ((wl-clipboard (get-value
                             'wl-clipboard config
                             (@ (gnu packages xdisorg) wl-clipboard)))
              (wl-copy      (file-append wl-clipboard "/bin/wl-copy"))
              (wl-paste     (file-append wl-clipboard "/bin/wl-paste")))
         (simple-service
          'zsh-make-zle-use-system-clipboard
          home-zsh-service-type
          (home-zsh-extension
           (zshrc
            (list
             ""
             #~(format #f "\
rde-copy-region-as-kill () {
  zle copy-region-as-kill
  print -rn $CUTBUFFER | ~a
}
zle -N rde-copy-region-as-kill

rde-kill-region () {
  zle kill-region
  print -rn $CUTBUFFER | ~a
}
zle -N rde-kill-region

rde-yank () {
  CUTBUFFER=$(~a)
  zle yank
}
zle -N rde-yank

bindkey -e '\\ew' rde-copy-region-as-kill
bindkey -e '^W' rde-kill-region
bindkey -e '^Y' rde-yank

" #$wl-copy #$wl-copy #$wl-paste)))))))

     ;; https://github.com/purcell/envrc
     ;; home-zsh-direnv-service
     (service
      home-zsh-service-type
      (home-zsh-configuration
       (xdg-flavor? #t)
       (package zsh)
       (zshrc
        `(,@(if rde-defaults?
                `(,(slurp-file-like (local-file "./zsh/zshrc"))
                  ; FIXME: Doesn't belong here, doesn't rely on full paths
                  "alias state-sync='herd sync state \
&& pass git push origin master'")
                '())
          ,@zshrc))
       (zprofile zprofile)
       (zshenv zshenv)
       (zlogout zlogout)))))

  (feature
   (name 'zsh)
   (values (make-feature-values zsh))
   (home-services-getter zsh-home-services)))

(define* (feature-bash
          #:key
          (bash bash))
  "Configure Bash."
  (ensure-pred any-package? bash)

  (define (get-home-services config)
    "Returns home services related to Bash."
    (list
     (simple-service
      'set-bash-histfile
      home-environment-variables-service-type
      `(("HISTFILE" . "$XDG_CACHE_HOME/.bash_history")))

     (service
      home-bash-service-type
      (home-bash-configuration
       (package bash)))))

  (feature
   (name 'bash)
   (values (make-feature-values bash))
   (home-services-getter get-home-services)))