summaryrefslogtreecommitdiffstats
path: root/src/features/hyperlinks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/hyperlinks.rs')
-rw-r--r--src/features/hyperlinks.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/features/hyperlinks.rs b/src/features/hyperlinks.rs
index d59f5e9b..bf0c2354 100644
--- a/src/features/hyperlinks.rs
+++ b/src/features/hyperlinks.rs
@@ -22,7 +22,12 @@ pub fn format_commit_line_with_osc8_commit_hyperlink<'a>(
line: &'a str,
config: &Config,
) -> Cow<'a, str> {
- if let Some(GitConfigEntry::GitRemote(GitRemoteRepo::GitHubRepo(repo))) =
+ if let Some(commit_link_format) = &config.hyperlinks_commit_link_format {
+ COMMIT_LINE_REGEX.replace(line, |captures: &Captures| {
+ let commit = captures.get(2).unwrap().as_str();
+ format_osc8_hyperlink(&commit_link_format.replace("{commit}", commit), commit)
+ })
+ } else if let Some(GitConfigEntry::GitRemote(GitRemoteRepo::GitHubRepo(repo))) =
config.git_config_entries.get("remote.origin.url")
{
COMMIT_LINE_REGEX.replace(line, |captures: &Captures| {
@@ -51,18 +56,22 @@ pub fn format_osc8_file_hyperlink<'a>(
} else {
url = url.replace("{line}", "")
};
- Cow::from(format!(
- "{osc}8;;{url}{st}{text}{osc}8;;{st}",
- url = url,
- text = text,
- osc = "\x1b]",
- st = "\x1b\\"
- ))
+ Cow::from(format_osc8_hyperlink(&url, text))
} else {
Cow::from(relative_path)
}
}
+fn format_osc8_hyperlink(url: &str, text: &str) -> String {
+ format!(
+ "{osc}8;;{url}{st}{text}{osc}8;;{st}",
+ url = url,
+ text = text,
+ osc = "\x1b]",
+ st = "\x1b\\"
+ )
+}
+
lazy_static! {
static ref COMMIT_LINE_REGEX: Regex = Regex::new("(.* )([0-9a-f]{40})(.*)").unwrap();
}