zsh.scm
1 | ;;; Guix Home Manager. |
2 | ;;; |
3 | ;;; Copyright © 2020 Z572 <873216071@qq.com> |
4 | ;;; |
5 | ;;; This program is free software: you can redistribute it and/or modify |
6 | ;;; it under the terms of the GNU General Public License as published by |
7 | ;;; the Free Software Foundation, either version 3 of the License, or |
8 | ;;; (at your option) any later version. |
9 | ;;; |
10 | ;;; This program is distributed in the hope that it will be useful, |
11 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | ;;; GNU General Public License for more details. |
14 | ;;; |
15 | ;;; You should have received a copy of the GNU General Public License |
16 | ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | (define-module (home zsh) |
19 | #:use-module (guix build utils) |
20 | #:use-module (guix gexp) |
21 | #:use-module (guix records) |
22 | #:use-module (ice-9 match) |
23 | #:use-module (home) |
24 | #:export (zsh-configuration |
25 | zsh-configuration-env |
26 | zsh-configuration-history |
27 | zsh-configuration-login |
28 | zsh-configuration-logout |
29 | zsh-configuration-profile |
30 | zsh-configuration-rc |
31 | |
32 | default-zshrc |
33 | default-zshenv |
34 | default-zlogin |
35 | default-zlogout |
36 | default-zprofile |
37 | |
38 | zsh-home-type)) |
39 | |
40 | (define default-zshrc |
41 | `(" |
42 | if [[ $- != *i* ]]; then |
43 | # Non interative shell. For SSH session, load /etc/profile to get |
44 | # PATH and other variables set up. |
45 | [[ -n \"$SSH_CLIENT\" ]] && source /etc/profile |
46 | return |
47 | fi |
48 | |
49 | if [ -n \"$GUIX_ENVIRONMENT\" ]; then |
50 | PS1='%n@%m %~ [env]$ ' |
51 | else |
52 | PS1='%n@%m %~$ ' |
53 | fi |
54 | |
55 | fpath=(~/.config/guix/current/share/zsh/site-functions $fpath) |
56 | autoload -Uz compinit && compinit -u |
57 | |
58 | alias ls='ls -p --color=auto' |
59 | alias ll='ls -l' |
60 | alias grep='grep --color=auto' |
61 | ")) |
62 | |
63 | (define default-zshenv |
64 | `("")) |
65 | |
66 | (define default-zlogin |
67 | `("")) |
68 | |
69 | (define default-zlogout |
70 | `("")) |
71 | |
72 | (define default-zprofile |
73 | `("if [ -f ~/.zshrc ]; then . ~/.zshrc; fi |
74 | # Workaround guix bug (not adding load path before processing the command name) |
75 | export GUILE_LOAD_PATH=~/.config/guix/current/share/guile/site/3.0:$GUILE_LOAD_PATH |
76 | export GUILE_LOAD_COMPILED_PATH=~/.config/guix/current/lib/guile/3.0/site-ccache:\ |
77 | $GUILE_LOAD_COMPILED_PATH |
78 | ")) |
79 | |
80 | (define-record-type* <zsh-configuration> |
81 | zsh-configuration make-zsh-configuration |
82 | zsh-configuration? |
83 | (rc zsh-configuration-rc |
84 | (default default-zshrc)) |
85 | (env zsh-configuration-env |
86 | (default default-zshenv)) |
87 | (login zsh-configuration-login |
88 | (default default-zlogin)) |
89 | (logout zsh-configuration-logout |
90 | (default default-zlogout)) |
91 | (profile zsh-configuration-profile |
92 | (default default-zprofile)) |
93 | (history zsh-configuration-history)) |
94 | |
95 | (define zsh-home-type |
96 | (home-type |
97 | (name 'zsh) |
98 | (extensions |
99 | (list |
100 | (home-extension |
101 | (target root-home-type) |
102 | (compute |
103 | (lambda (config) |
104 | (match config |
105 | (($ <zsh-configuration> rc env login logout profile history) |
106 | (let ((zshenv (apply mixed-text-file "zshenv" env)) |
107 | (zlogin (apply mixed-text-file "zlogin" login)) |
108 | (zlogout (apply mixed-text-file "zlogout" logout)) |
109 | (zshrc (apply mixed-text-file "zshrc" rc)) |
110 | (zprofile (apply mixed-text-file "zprofile" profile))) |
111 | `((".zsh_history" ,history) |
112 | (".zshrc" ,zshrc) |
113 | (".zlogin" ,zlogin) |
114 | (".zlogout" ,zlogout) |
115 | (".zshenv" ,zshenv) |
116 | (".zprofile" ,zprofile)))))))))))) |
117 |