Próximo: Scheduled User’s Job Execution, Anterior: Serviços essenciais pessoais, Acima: Serviços pessoais [Conteúdo][Índice]
Shells play a quite important role in the environment initialization process, you can configure them manually as described in section Configurando o "Shell", but the recommended way is to use home services listed below. It’s both easier and more reliable.
Each home environment instantiates home-shell-profile-service-type
,
which creates a ~/.profile startup file for all POSIX-compatible
shells. This file contains all the necessary steps to properly initialize
the environment, but many modern shells like Bash or Zsh prefer their own
startup files, that’s why the respective home services
(home-bash-service-type
and home-zsh-service-type
) ensure that
~/.profile is sourced by ~/.bash_profile and
~/.zprofile, respectively.
Available home-shell-profile-configuration
fields are:
profile
(default: '()
) (type: text-config)home-shell-profile
is instantiated automatically by
home-environment
, DO NOT create this service manually, it can only be
extended. profile
is a list of file-like objects, which will go to
~/.profile. By default ~/.profile contains the initialization
code which must be evaluated by the login shell to make home-environment’s
profile available to the user, but other commands can be added to the file
if it is really necessary. In most cases shell’s configuration files are
preferred places for user’s customizations. Extend home-shell-profile
service only if you really know what you do.
Available home-bash-configuration
fields are:
package
(default: bash
) (type: package)The Bash package to use.
guix-defaults?
(default: #t
) (type: boolean)Add sane defaults like reading /etc/bashrc and coloring the output of
ls
to the top of the .bashrc file.
environment-variables
(default: '()
) (type: alist)Association list of environment variables to set for the Bash session. The
rules for the home-environment-variables-service-type
apply here
(veja Serviços essenciais pessoais). The contents of this field will be added
after the contents of the bash-profile
field.
aliases
(default: '()
) (type: alist)Association list of aliases to set for the Bash session. The aliases will
be defined after the contents of the bashrc
field has been put in the
.bashrc file. The alias will automatically be quoted, so something
like this:
'(("ls" . "ls -alF"))
turns into
alias ls="ls -alF"
bash-profile
(default: '()
) (type: text-config)List of file-like objects, which will be added to .bash_profile. Used for executing user’s commands at start of login shell (In most cases the shell started on tty just after login). .bash_login won’t be ever read, because .bash_profile always present.
bashrc
(default: '()
) (type: text-config)List of file-like objects, which will be added to .bashrc. Used for
executing user’s commands at start of interactive shell (The shell for
interactive usage started by typing bash
or by terminal app or any
other program).
bash-logout
(default: '()
) (type: text-config)List of file-like objects, which will be added to .bash_logout. Used for executing user’s commands at the exit of login shell. It won’t be read in some cases (if the shell terminates by exec’ing another process for example).
You can extend the Bash service by using the home-bash-extension
configuration record, whose fields must mirror that of
home-bash-configuration
(veja home-bash-configuration). The
contents of the extensions will be added to the end of the corresponding
Bash configuration files (veja Bash Startup Files em The GNU Bash
Reference Manual.
For example, here is how you would define a service that extends the Bash
service such that ~/.bash_profile defines an additional environment
variable, PS1
:
(define bash-fancy-prompt-service
(simple-service 'bash-fancy-prompt
home-bash-service-type
(home-bash-extension
(environment-variables
'(("PS1" . "\\u \\wλ "))))))
You would then add bash-fancy-prompt-service
to the list in the
services
field of your home-environment
. The reference of
home-bash-extension
follows.
Available home-bash-extension
fields are:
environment-variables
(default: '()
) (type: alist)Additional environment variables to set. These will be combined with the environment variables from other extensions and the base service to form one coherent block of environment variables.
aliases
(default: '()
) (type: alist)Additional aliases to set. These will be combined with the aliases from other extensions and the base service.
bash-profile
(default: '()
) (type: text-config)Additional text blocks to add to .bash_profile, which will be combined with text blocks from other extensions and the base service.
bashrc
(default: '()
) (type: text-config)Additional text blocks to add to .bashrc, which will be combined with text blocks from other extensions and the base service.
bash-logout
(default: '()
) (type: text-config)Additional text blocks to add to .bash_logout, which will be combined with text blocks from other extensions and the base service.
Available home-zsh-configuration
fields are:
package
(default: zsh
) (type: package)The Zsh package to use.
xdg-flavor?
(default: #t
) (type: boolean)Place all the configs to $XDG_CONFIG_HOME/zsh. Makes
~/.zshenv to set ZDOTDIR
to $XDG_CONFIG_HOME/zsh. Shell
startup process will continue with $XDG_CONFIG_HOME/zsh/.zshenv.
environment-variables
(default: '()
) (type: alist)Association list of environment variables to set for the Zsh session.
zshenv
(default: '()
) (type: text-config)List of file-like objects, which will be added to .zshenv. Used for
setting user’s shell environment variables. Must not contain commands
assuming the presence of tty or producing output. Will be read always.
Will be read before any other file in ZDOTDIR
.
zprofile
(default: '()
) (type: text-config)List of file-like objects, which will be added to .zprofile. Used for executing user’s commands at start of login shell (In most cases the shell started on tty just after login). Will be read before .zlogin.
zshrc
(default: '()
) (type: text-config)List of file-like objects, which will be added to .zshrc. Used for
executing user’s commands at start of interactive shell (The shell for
interactive usage started by typing zsh
or by terminal app or any
other program).
zlogin
(default: '()
) (type: text-config)List of file-like objects, which will be added to .zlogin. Used for executing user’s commands at the end of starting process of login shell.
zlogout
(default: '()
) (type: text-config)List of file-like objects, which will be added to .zlogout. Used for executing user’s commands at the exit of login shell. It won’t be read in some cases (if the shell terminates by exec’ing another process for example).
The GNU Readline
package includes Emacs and vi editing modes, with the ability to customize
the configuration with settings in the ~/.inputrc file. With the
gnu home services shells
module, you can setup your readline
configuration in a predictable manner, as shown below. For more information
about configuring an ~/.inputrc file, veja Readline Init File em GNU Readline.
This is the service to setup various .inputrc configurations. The settings in .inputrc are read by all programs which are linked with GNU Readline.
Here is an example of a service and its configuration that you could add to
the services
field of your home-environment
:
(service home-inputrc-service-type
(home-inputrc-configuration
(key-bindings
`(("Control-l" . "clear-screen")))
(variables
`(("bell-style" . "visible")
("colored-completion-prefix" . #t)
("editing-mode" . "vi")
("show-mode-in-prompt" . #t)))
(conditional-constructs
`(("$if mode=vi" .
,(home-inputrc-configuration
(variables
`(("colored-stats" . #t)
("enable-bracketed-paste" . #t)))))
("$else" .
,(home-inputrc-configuration
(variables
`(("show-all-if-ambiguous" . #t)))))
("endif" . #t)
("$include" . "/etc/inputrc")
("$include" . ,(file-append
(specification->package "readline")
"/etc/inputrc"))))))
The example above starts with a combination of key-bindings
and
variables
. The conditional-constructs
show how it is possible
to add conditionals and includes. In the example above colored-stats
is only enabled if the editing mode is vi
style, and it also reads
any additional configuration located in /etc/inputrc or in
/gnu/store/…-readline/etc/inputrc.
The value associated with a home-inputrc-service-type
instance must
be a home-inputrc-configuration
record, as described below.
Available home-inputrc-configuration
fields are:
key-bindings
(default: '()
) (type: alist)Association list of readline key bindings to be added to the ~/.inputrc file.
'((\"Control-l\" . \"clear-screen\"))
turns into
Control-l: clear-screen
variables
(default: '()
) (type: alist)Association list of readline variables to set.
'((\"bell-style\" . \"visible\") (\"colored-completion-prefix\" . #t))
turns into
set bell-style visible set colored-completion-prefix on
conditional-constructs
(default: '()
) (type: alist)Association list of conditionals to add to the initialization file. This
includes $if
, else
, endif
and
include
and they receive a value of another
home-inputrc-configuration
.
(conditional-constructs
`((\"$if mode=vi\" .
,(home-inputrc-configuration
(variables
`((\"show-mode-in-prompt\" . #t)))))
(\"$else\" .
,(home-inputrc-configuration
(key-bindings
`((\"Control-l\" . \"clear-screen\")))))
(\"$endif\" . #t)))
turns into
$if mode=vi set show-mode-in-prompt on $else Control-l: clear-screen $endif
extra-content
(default: ""
) (type: text-config)Extra content appended as-is to the configuration file. Run man
readline
for more information about all the configuration options.
Próximo: Scheduled User’s Job Execution, Anterior: Serviços essenciais pessoais, Acima: Serviços pessoais [Conteúdo][Índice]