mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-03 11:52:26 +01:00
Recognize files in $XDG_CONFIG_HOME/git/
and $HOME/.config/git/
better (#2067)
* git global config - lookup $XDG_CONFIG_HOME faithfully * Use `bool::then` * Cover both `$XDG_CONFIG_HOME` & `$HOME/.config` * Remove unused import * Global git config tests * Added trailing newline * Fix git config test * Wrote to changelog * Revert change of `Result::ok` to `Result::unwrap` * Apply suggestions from code review Co-authored-by: Martin Nordholts <enselic@gmail.com> * Guard against empty `$HOME` Co-authored-by: Martin Nordholts <enselic@gmail.com>
This commit is contained in:
@@ -122,8 +122,22 @@ impl<'a> SyntaxMapping<'a> {
|
||||
.insert("*.hook", MappingTarget::MapTo("INI"))
|
||||
.unwrap();
|
||||
|
||||
if let Some(xdg_config_home) = std::env::var_os("XDG_CONFIG_HOME") {
|
||||
let git_config_path = Path::new(&xdg_config_home).join("git");
|
||||
// Global git config files rooted in `$XDG_CONFIG_HOME/git/` or `$HOME/.config/git/`
|
||||
// See e.g. https://git-scm.com/docs/git-config#FILES
|
||||
if let Some(xdg_config_home) =
|
||||
std::env::var_os("XDG_CONFIG_HOME").filter(|val| !val.is_empty())
|
||||
{
|
||||
insert_git_config_global(&mut mapping, &xdg_config_home);
|
||||
}
|
||||
if let Some(default_config_home) = std::env::var_os("HOME")
|
||||
.filter(|val| !val.is_empty())
|
||||
.map(|home| Path::new(&home).join(".config"))
|
||||
{
|
||||
insert_git_config_global(&mut mapping, &default_config_home);
|
||||
}
|
||||
|
||||
fn insert_git_config_global(mapping: &mut SyntaxMapping, config_home: impl AsRef<Path>) {
|
||||
let git_config_path = config_home.as_ref().join("git");
|
||||
|
||||
mapping
|
||||
.insert(
|
||||
|
Reference in New Issue
Block a user