xshe 0.2.0

Xshe allows for setting environment variables across multiple shells.
xshe-0.2.0 is not a library.

Xshe – Cross-Shell Env Vars

Set Shell Environment variables across multiple shells with a single configuration file.

Installation

Install xshe from crates.io with cargo.

cargo install xshe

You might need to add the resulting xshe binary to your PATH.

Release binaries are also available at GitHub.

Setup

Creating a xshe.toml file

Create a file called xshe.toml in ~/.config. This is a TOML file that represents environment variables.

One variable is set per line. The file is read in order from top to bottom, so variables that appear earlier in the file can be used to define ones that appear later.

A typical line looks like this:

CARGO_HOME = "$XDG_DATA_HOME/cargo"

This will then be converted into the correct format for whatever shell is being used. For example, in bash, this line becomes:

export CARGO_HOME="$XDG_DATA_HOME/cargo";

Shell Specific Environment Variables

To set environment variables for only one shell, add a new table called [shell.NAME] after all standard definitions, where NAME is on of bash, zsh, or fish. Then list the environment variables that will only be added if xshe is being used for the given shell.

For example, to make $HISTFILE be different between shells and $ZSH_CACHE_DIR only be set in zsh, do this:

[shell.bash]
HISTFILE = "$XDG_STATE_HOME/bash_history"

[shell.zsh]
HISTFILE = "$XDG_STATE_HOME/zsh_history"
ZSH_CACHE_DIR = "$XDG_CACHE_HOME/oh-my-zsh"

Sourcing the xshe.toml file

Put the line corresponding to your shell in whatever file runs when loading environment variables. For bash, this is ~/.bash_profile, for zsh, this is ~/.zshenv, and for fish, this is ~/.config/fish/config.fish.

Bash
eval "$(xshe bash)"
Zsh
eval "$(xshe zsh)"
Fish
eval "$(xshe fish)"

Options

To specify a custom file that is not located at ~/.config/xshe.toml, pass the --file option, like so:

eval "$(xshe zsh --file ~/some/other/location.toml)"

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.