diff options
author | Ahmed El Gabri <ahmed@gabri.me> | 2020-09-23 21:08:47 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2020-10-01 21:06:37 +0200 |
commit | 31acbe20d38d33b442a3ee0abf785b85d028f91f (patch) | |
tree | bf7495a10be6b2ea10616178dac23edfbb68e22b /src | |
parent | fd52c01e7802e39a28dda1f96fb8dec19a02f2ac (diff) |
Support XDG_CONFIG_HOME git config files
Diffstat (limited to 'src')
-rw-r--r-- | src/syntax_mapping.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/syntax_mapping.rs b/src/syntax_mapping.rs index 25caf53f..c3ce9acb 100644 --- a/src/syntax_mapping.rs +++ b/src/syntax_mapping.rs @@ -103,6 +103,43 @@ 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"); + + mapping + .insert( + &git_config_path + .join("config") + .into_os_string() + .to_str() + .unwrap(), + MappingTarget::MapTo("Git Config"), + ) + .unwrap(); + + mapping + .insert( + &git_config_path + .join("ignore") + .into_os_string() + .to_str() + .unwrap(), + MappingTarget::MapTo("Git Ignore"), + ) + .unwrap(); + + mapping + .insert( + &git_config_path + .join("attributes") + .into_os_string() + .to_str() + .unwrap(), + MappingTarget::MapTo("Git Attributes"), + ) + .unwrap(); + } + mapping } @@ -156,6 +193,23 @@ fn basic() { } #[test] +fn git_xdg_config_home() { + use assert_cmd::Command; + let mut cmd = Command::cargo_bin("bat").unwrap(); + let mut map = SyntaxMapping::builtin(); + + cmd.env("XDG_CONFIG_HOME", "/foo/bar"); + + map.insert("/foo/bar/git/config", MappingTarget::MapTo("Git Config")) + .ok(); + + assert_eq!( + map.get_syntax_for("/foo/bar/git/config"), + Some(MappingTarget::MapTo("Git Config")) + ); +} + +#[test] fn user_can_override_builtin_mappings() { let mut map = SyntaxMapping::builtin(); |