Conform to XDG spec for configuration

- Use $XDG_CONFIG_HOME/alacritty/alacritty.yml for loading the
	  configuration file falling back to $HOME/.config/alacritty/alacritty.yml
	- Closes #203
This commit is contained in:
Alberto Corona 2017-01-07 15:19:30 -06:00 committed by Joe Wilm
parent 2fa271419c
commit 987b8555de
2 changed files with 15 additions and 9 deletions

View File

@ -138,9 +138,15 @@ cp Alacritty.desktop ~/.local/share/applications
### Configuration ### Configuration
Although it's possible the default configuration would work on your system, Although it's possible the default configuration would work on your system,
you'll probably end up wanting to customize it anyhow. There is an you'll probably end up wanting to customize it anyhow. There is a default
`alacritty.yml` at the git repository root. Copy this to either `alacritty.yml` at the git repository root. Alacritty looks for the configuration
`$HOME/.alacritty.yml` or `$XDG_CONFIG_HOME/alacritty.yml` and run Alacritty. file as the following paths:
1. `$XDG_CONFIG_HOME/alacritty/alacritty.yml`
2. `$HOME/.config/alacritty/alacritty.yml`
If these files are not found then one is created as `$HOME/.config/alacritty/alacritty.yml`
once alacritty is first run.
Many configuration options will take effect immediately upon saving changes to Many configuration options will take effect immediately upon saving changes to
the config file. The only exception is the `font` and `dpi` section which the config file. The only exception is the `font` and `dpi` section which

View File

@ -811,19 +811,19 @@ impl Config {
/// ///
/// The config file is loaded from the first file it finds in this list of paths /// The config file is loaded from the first file it finds in this list of paths
/// ///
/// 1. `$HOME/.config/alacritty.yml` /// 1. $XDG_CONFIG_HOME/alacritty/alacritty.yml
/// 2. `$HOME/.alacritty.yml` /// 2. $HOME/.config/alacritty/alacritty.yml
pub fn load() -> Result<Config> { pub fn load() -> Result<Config> {
let home = env::var("HOME")?; let home = env::var("HOME")?;
// Try using XDG location by default // Try using XDG location by default
let path = ::xdg::BaseDirectories::new() let path = ::xdg::BaseDirectories::with_prefix("alacritty")
.ok() .ok()
.and_then(|xdg| xdg.find_config_file("alacritty.yml")) .and_then(|xdg| xdg.find_config_file("alacritty.yml"))
.unwrap_or_else(|| { .unwrap_or_else(|| {
// Fallback path: $HOME/.alacritty.yml // Fallback path: $HOME/.config/alacritty/alacritty.yml
let mut alt_path = PathBuf::from(&home); let mut alt_path = PathBuf::from(&home);
alt_path.push(".alacritty.yml"); alt_path.push(".config/alacritty/alacritty.yml");
alt_path alt_path
}); });
@ -831,7 +831,7 @@ impl Config {
} }
pub fn write_defaults() -> io::Result<PathBuf> { pub fn write_defaults() -> io::Result<PathBuf> {
let path = ::xdg::BaseDirectories::new() let path = ::xdg::BaseDirectories::with_prefix("alacritty")
.map_err(|err| io::Error::new(io::ErrorKind::NotFound, ::std::error::Error::description(&err))) .map_err(|err| io::Error::new(io::ErrorKind::NotFound, ::std::error::Error::description(&err)))
.and_then(|p| p.place_config_file("alacritty.yml"))?; .and_then(|p| p.place_config_file("alacritty.yml"))?;
File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?; File::create(&path)?.write_all(DEFAULT_ALACRITTY_CONFIG.as_bytes())?;