From 51f3e0b2d1a2e515d25dc5d92d311465e567116f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Sat, 9 Mar 2024 18:06:14 +0200 Subject: [PATCH] feat: replace `hx` with `$EDITOR` in config --- config.kdl | 4 ++-- src/link/mod.rs | 13 ++++++++++--- src/note/mod.rs | 7 ++++--- src/note/task_items_term_tree.rs | 7 +++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/config.kdl b/config.kdl index 2cdf4f5..d2d3eb6 100644 --- a/config.kdl +++ b/config.kdl @@ -6,8 +6,8 @@ world { file-line "bat" "--color=always" "--line-range" "$FIRST:$LAST" "-H" "$LINE" "$FILE" } open { - file "hx" "$FILE" - file-jump "hx" "$FILE:$LINE:$COLUMN" + file "$EDITOR" "$FILE" + file-jump "$EDITOR" "$FILE:$LINE:$COLUMN" // file-jump "nvim" "$FILE" "+call cursor($LINE, $COLUMN)" dir "zellij" "action" "new-pane" "--cwd" "$DIR" "--" "broot" url "firefox" "$URL" diff --git a/src/link/mod.rs b/src/link/mod.rs index b3f62b6..1b9e286 100644 --- a/src/link/mod.rs +++ b/src/link/mod.rs @@ -46,14 +46,18 @@ impl Open for Link { } Destination::File { file, .. } => { + let file_cmd = PathBuf::from(&cfg.file_cmd.command); + let file_cmd = env_substitute::substitute(file_cmd); cfg.file_cmd .replace_matching_element("$FILE", file.to_str().unwrap_or("bad utf path")); Ok(Some( - cmd(cfg.file_cmd.command, cfg.file_cmd.args).run()?.status, + cmd(file_cmd.to_str().unwrap().to_owned(), cfg.file_cmd.args).run()?.status, )) } Destination::FileLine { file, line_number } => { + let file_cmd = PathBuf::from(&cfg.file_jump_cmd.command); + let file_cmd = env_substitute::substitute(file_cmd); let prev_dir = std::env::current_dir()?; let next_dir = file.parent(); @@ -69,7 +73,7 @@ impl Open for Link { cfg.file_jump_cmd .replace_in_matching_element("$COLUMN", &format!("{}", 1)); - let status = cmd(cfg.file_jump_cmd.command, cfg.file_jump_cmd.args) + let status = cmd(file_cmd.to_str().unwrap().to_owned(), cfg.file_jump_cmd.args) .run()? .status; std::env::set_current_dir(prev_dir)?; @@ -148,6 +152,9 @@ impl Jump for Link { ) -> std::io::Result> { let position = self.start; + let file_cmd = PathBuf::from(&cfg.file_jump_cmd.command); + let file_cmd = env_substitute::substitute(file_cmd); + cfg.file_jump_cmd.replace_in_matching_element( "$FILE", self.containing_file_name.to_str().unwrap_or("bad utf path"), @@ -160,7 +167,7 @@ impl Jump for Link { .replace_in_matching_element("$COLUMN", &format!("{}", position.column)); Ok(Some( - cmd(cfg.file_jump_cmd.command, cfg.file_jump_cmd.args) + cmd(file_cmd.to_str().unwrap().to_owned(), cfg.file_jump_cmd.args) .run()? .status, )) diff --git a/src/note/mod.rs b/src/note/mod.rs index b375559..70bf963 100644 --- a/src/note/mod.rs +++ b/src/note/mod.rs @@ -110,11 +110,12 @@ impl Display for Note { impl Open for Note { fn open(&self, mut cfg: OpenCfg) -> io::Result> { if let Some(file_path) = self.file_path() { + let file_cmd = PathBuf::from(&cfg.file_cmd.command); + let file_cmd = env_substitute::substitute(file_cmd); + println!("{:?}", file_cmd); cfg.file_cmd .replace_matching_element("$FILE", file_path.to_str().unwrap_or("bad utf path")); - Ok(Some( - cmd(cfg.file_cmd.command, cfg.file_cmd.args).run()?.status, - )) + Ok(Some(cmd(file_cmd.to_str().unwrap().to_owned(), cfg.file_cmd.args).run()?.status)) } else { Ok(None) } diff --git a/src/note/task_items_term_tree.rs b/src/note/task_items_term_tree.rs index 385931d..417496e 100644 --- a/src/note/task_items_term_tree.rs +++ b/src/note/task_items_term_tree.rs @@ -1,4 +1,4 @@ -use std::{collections::HashSet, fmt::Display, fs}; +use std::{collections::HashSet, fmt::Display, fs, path::PathBuf}; use crate::{ config::{color::ColorScheme, SurfParsing}, @@ -151,6 +151,9 @@ impl Jump for NoteTaskItemTerm { let offset = task.checkmark_offsets_in_string.start; let position = find_position(initial_contents, offset); + let file_cmd = PathBuf::from(&cfg.file_jump_cmd.command); + let file_cmd = env_substitute::substitute(file_cmd); + cfg.file_jump_cmd.replace_in_matching_element( "$FILE", task.file_name.to_str().unwrap_or("bad utf path"), @@ -163,7 +166,7 @@ impl Jump for NoteTaskItemTerm { .replace_in_matching_element("$COLUMN", &format!("{}", position.column)); Ok(Some( - cmd(cfg.file_jump_cmd.command, cfg.file_jump_cmd.args) + cmd(file_cmd.to_str().unwrap().to_owned(), cfg.file_jump_cmd.args) .run()? .status, ))