home: Add zsh home type.

Z572Tue Sep 15 14:07:43+0200 2020

9f09789

home: Add zsh home type. * home/zsh.scm: New file. * doc/zsh.md: New file. * doc/README.md: Add it. Signed-off-by: Julien Lepiller <julien@lepiller.eu>

doc/README.md

6464
6565
* [Bash](doc/bash.md)
6666
* [Neovim](doc/neovim.md)
67+
* [Zsh](doc/zsh.md)
6768
6869
### Common Issues
6970

doc/zsh.md unknown status 1

1+
Zsh
2+
====
3+
4+
The Z shell (zsh) is a Unix shell that can be used as an interactive
5+
login shell and as a powerful command interpreter for shell scripting.
6+
7+
Main Configuration
8+
------------------
9+
10+
Zsh is configured by using the `zsh-home-type` service type.
11+
12+
**Scheme Procedure**: zsh-home-type
13+
14+
The type of service that generates configuration files for zsh.  Its value
15+
is a zsh-configuration object.
16+
17+
**Data Type**: zsh-configuration
18+
19+
Data type that represents the Zsh configuration.  This data type has the
20+
following fields:
21+
22+
* **rc** (default *default-zshrc*): the content of the `.zshrc` file.  This is
23+
  a list of strings and
24+
* **env** (default *default-zshenv*): the content of the `.zshenv`
25+
  file.
26+
* **login** (default *default-zlogin*): the content of the `.zlogin`
27+
  file.
28+
* **logout** (default *default-zlogout*): the content of the `.zlogout`
29+
  file.
30+
* **profile** (default *default-zprofile*): the content of the `.zprofile`
31+
  file.
32+
* **history** (default #f): the location of the `.zsh_history` file for saving
33+
  history.  The location must be read-write accessible to your user.
34+
35+
Example Configuration
36+
---------------------
37+
38+
```scheme
39+
(user-home
40+
  zsh-home-type
41+
  (zsh-configuration
42+
    (rc (append default-zshrc
43+
                '("alias vim=nvim")))
44+
    (profile (append default-zprofile
45+
                     `("EDITOR=nvim\n"
46+
               ;; Minetest would not work without this :/
47+
                       "export MINETEST_SUBGAME_PATH="
48+
               ,(@@ (gnu packages games) minetest-data)
49+
               "/share/minetest/games/")))
50+
    (history "/data/alice/.zsh_history")))
51+
```

home/zsh.scm unknown status 1

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))))))))))))