summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cli.rs14
-rw-r--r--src/config.rs2
-rw-r--r--src/env.rs7
-rw-r--r--src/features/hyperlinks.rs3
4 files changed, 18 insertions, 8 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 07a7c7d..737c345 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
- /// <https://github.com/dandavison/open-in-editor> 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
+ /// <https://dandavison.github.io/delta/hyperlinks.html> for details.
pub hyperlinks_file_link_format: String,
#[arg(
diff --git a/src/config.rs b/src/config.rs
index 86ff40a..a536d7e 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -78,6 +78,7 @@ pub struct Config {
pub grep_output_type: Option<GrepType>,
pub grep_separator_symbol: String,
pub handle_merge_conflicts: bool,
+ pub hostname: Option<String>,
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<cli::Opt> 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 49c7b21..a289d84 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -19,6 +19,7 @@ pub struct DeltaEnv {
pub features: Option<String>,
pub git_config_parameters: Option<String>,
pub git_prefix: Option<String>,
+ pub hostname: Option<String>,
pub navigate: Option<String>,
pub pagers: (Option<String>, Option<String>),
}
@@ -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<String> {
+ 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 4771a07..e0a354b 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 {