xonsh/docs/xonshconfig.rst

122 lines
4.6 KiB
ReStructuredText
Raw Normal View History

2015-10-10 23:22:36 -04:00
Static Configuration File
=========================
In addition to the run control file, xonsh allows you to have a static config file.
This JSON-formatted file lives at ``$XONSH_CONFIG_DIR/config.json``, which is
normally ``~/.config/xonsh/config.json``. The purpose of this file is to allow
2016-05-07 16:29:48 -04:00
users to set runtime parameters *before* anything else happens. This includes
2015-10-10 23:22:36 -04:00
loading data from various foreign shells or setting critical environment
variables.
2016-05-07 16:29:48 -04:00
This is a dictionary or JSON object at its top-level. It has the following
2015-10-10 23:22:36 -04:00
top-level keys. All top-level keys are optional.
``env``
--------
2016-05-07 16:29:48 -04:00
This is a simple string-keyed dictionary that lets you set environment
variables. For example,
2015-10-10 23:22:36 -04:00
.. code:: json
{"env": {
"EDITOR": "xo",
"PAGER": "more"
}
}
2016-05-11 01:55:53 -04:00
``xontribs``
------------
This is a list (JSON array) of xontrib names (strings) to load prior to
loading any run control files. For example,
.. code:: json
{"xontribs": ["mpl", "example"]}
2015-10-10 23:22:36 -04:00
``foreign_shells``
--------------------
This is a list (JSON Array) of dicts (JSON objects) that represent the
foreign shells to inspect for extra start up information, such as environment
2016-05-07 16:29:48 -04:00
variables, aliases, and foreign shell functions. The suite of data gathered
2015-11-01 16:52:15 -05:00
may be expanded in the future. Each shell dictionary unpacked and passed into
2016-05-07 16:29:48 -04:00
the ``xonsh.foreign_shells.foreign_shell_data()`` function. Thus, these
2015-11-01 16:52:15 -05:00
dictionaries have the following structure:
2015-10-10 23:22:36 -04:00
:shell: *str, required* - The name or path of the shell, such as "bash" or "/bin/sh".
:interactive: *bool, optional* - Whether the shell should be run in interactive mode.
``default=true``
:login: *bool, optional* - Whether the shell should be a login shell.
``default=false``
:envcmd: *str, optional* - The command to generate environment output with.
``default="env"``
:aliascmd: *str, optional* - The command to generate alais output with.
``default="alias"``
2016-05-07 16:29:48 -04:00
:extra_args: *list of str, optional* - Addtional command line options to pass
2015-10-10 23:22:36 -04:00
into the shell. ``default=[]``
:currenv: *dict or null, optional* - Manual override for the current environment.
``default=null``
2016-05-07 16:29:48 -04:00
:safe: *bool, optional* - Flag for whether or not to safely handle exceptions
2015-10-10 23:22:36 -04:00
and other errors. ``default=true``
2016-05-07 16:29:48 -04:00
:prevcmd: *str, optional* - An additional command or script to run before
anything else, useful for sourcing and other commands that may require
2015-11-01 16:52:15 -05:00
environment recovery. ``default=''``
:postcmd: *str, optional* - A command to run after everything else, useful for
cleaning up any damage that the ``prevcmd`` may have caused. ``default=''``
2016-05-07 16:29:48 -04:00
:funcscmd: *str or None, optional* - This is a command or script that can be
2015-11-01 16:52:15 -05:00
used to determine the names and locations of any functions that are native
2016-05-07 16:29:48 -04:00
to the foreign shell. This command should print *only* a whitespace
2015-11-01 16:52:15 -05:00
separated sequence of pairs function name & filenames where the functions
are defined. If this is None (null), then a default script will attempted
2016-05-07 16:29:48 -04:00
to be looked up based on the shell name. Callable wrappers for these
2015-11-01 16:52:15 -05:00
functions will be returned in the aliases dictionary. ``default=null``
2016-05-07 16:29:48 -04:00
:sourcer: *str or None, optional* - How to source a foreign shell file for
purposes of calling functions in that shell. If this is None, a default
2015-11-01 16:52:15 -05:00
value will attempt to be looked up based on the shell name. ``default=null``
2016-05-11 00:57:48 -04:00
:runcmd: *str or None, optional* - Command line switches to use when
2016-05-07 16:29:48 -04:00
running the script, such as ``-c`` for Bash and ``/C`` for cmd.exe.
``default=null``
2016-05-11 00:57:48 -04:00
:seterrprevcmd: *str or None, optional* - Command that enables exit-on-error
2016-05-07 17:13:18 -04:00
for the shell before all other commands. For example, this is "set -e" in Bash.
To disable this exit-on-error behavior, simply pass in an empty string.
``default=null``
2016-05-11 00:57:48 -04:00
:seterrpostcmd: *str or None, optional* - Command that enables exit-on-error
2016-05-08 11:36:26 -04:00
for the shell after all other commands. For example, this is
"if errorlevel 1 exit 1" in cmd.exe. To disable this exit-on-error behavior,
simply pass in an empty string. ``default=null``
2016-05-07 16:29:48 -04:00
2015-10-10 23:22:36 -04:00
Some examples can be seen below:
.. code:: json
# load bash then zsh
{"foreign_shells": [
{"shell": "/bin/bash"},
{"shell": "zsh"}
]
}
# load bash as a login shell with custom rcfile
{"foreign_shells": [
2016-05-07 16:29:48 -04:00
{"shell": "bash",
"login": true,
2015-10-10 23:22:36 -04:00
"extra_args": ["--rcfile", "/path/to/rcfile"]
}
]
}
# disable all foreign shell loading via an empty list
{"foreign_shells": []}
Putting it all together
-----------------------
The following ecample shows a fully fleshed out config file.
2015-10-12 00:45:03 -04:00
:download:`Download config.json <xonshconfig.json>`
2015-10-10 23:22:36 -04:00
.. include:: xonshconfig.json
:code: json