diff --git a/src/cli.rs b/src/cli.rs index 07a7c7d44..737c3450b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -432,14 +432,12 @@ pub struct Opt { )] /// Format string for file hyperlinks (requires --hyperlinks). /// - /// The placeholders "{path}" and "{line}" will be replaced by the absolute file path and the - /// line number, respectively. The default value of this option creates hyperlinks using - /// standard file URLs; your operating system should open these in the application registered - /// for that file type. However, these do not make use of the line number. In order for the link - /// to open the file at the correct line number, you could use a custom URL format such as - /// "file-line://{path}:{line}" and register an application to handle the custom "file-line" URL - /// scheme by opening the file in your editor/IDE at the indicated line number. See - /// for an example. + /// Placeholders "{path}" and "{line}" will be replaced by the absolute file path and the line + /// number; "{host}" with the hostname delta is currently running on. The default is to create + /// a hyperlink containing a standard file URI with only the filename, which your terminal or + /// OS should handle. You can specify any scheme, such as "file-line://{path}:{line}" and + /// register an application to handle it. See + /// for details. pub hyperlinks_file_link_format: String, #[arg( diff --git a/src/config.rs b/src/config.rs index 86ff40a81..a536d7e42 100644 --- a/src/config.rs +++ b/src/config.rs @@ -78,6 +78,7 @@ pub struct Config { pub grep_output_type: Option, pub grep_separator_symbol: String, pub handle_merge_conflicts: bool, + pub hostname: Option, pub hunk_header_file_style: Style, pub hunk_header_line_number_style: Style, pub hunk_header_style_include_file_path: HunkHeaderIncludeFilePath, @@ -326,6 +327,7 @@ impl From for Config { grep_output_type, grep_separator_symbol: opt.grep_separator_symbol, handle_merge_conflicts: !opt.raw, + hostname: opt.env.hostname, hunk_header_file_style: styles["hunk-header-file-style"], hunk_header_line_number_style: styles["hunk-header-line-number-style"], hunk_header_style: styles["hunk-header-style"], diff --git a/src/env.rs b/src/env.rs index 49c7b2123..a289d8433 100644 --- a/src/env.rs +++ b/src/env.rs @@ -19,6 +19,7 @@ pub struct DeltaEnv { pub features: Option, pub git_config_parameters: Option, pub git_prefix: Option, + pub hostname: Option, pub navigate: Option, pub pagers: (Option, Option), } @@ -33,6 +34,7 @@ impl DeltaEnv { let features = env::var(DELTA_FEATURES).ok(); let git_config_parameters = env::var(GIT_CONFIG_PARAMETERS).ok(); let git_prefix = env::var(GIT_PREFIX).ok(); + let hostname = hostname(); let navigate = env::var(DELTA_NAVIGATE).ok(); let current_dir = env::current_dir().ok(); @@ -53,12 +55,17 @@ impl DeltaEnv { features, git_config_parameters, git_prefix, + hostname, navigate, pagers, } } } +fn hostname() -> Option { + grep_cli::hostname().ok()?.to_str().map(|s| s.to_string()) +} + #[cfg(test)] pub mod tests { use super::DeltaEnv; diff --git a/src/features/hyperlinks.rs b/src/features/hyperlinks.rs index 4771a0769..e0a354b43 100644 --- a/src/features/hyperlinks.rs +++ b/src/features/hyperlinks.rs @@ -56,6 +56,9 @@ where let mut url = config .hyperlinks_file_link_format .replace("{path}", &absolute_path.as_ref().to_string_lossy()); + if let Some(host) = &config.hostname { + url = url.replace("{host}", host) + } if let Some(n) = line_number { url = url.replace("{line}", &format!("{n}")) } else {