Skip to content

Commit

Permalink
feat: replace hx with $EDITOR in config
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Mar 9, 2024
1 parent b59bec1 commit 51f3e0b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions config.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 10 additions & 3 deletions src/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)?;
Expand Down Expand Up @@ -148,6 +152,9 @@ impl Jump for Link {
) -> std::io::Result<Option<std::process::ExitStatus>> {
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"),
Expand All @@ -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,
))
Expand Down
7 changes: 4 additions & 3 deletions src/note/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,12 @@ impl Display for Note {
impl Open for Note {
fn open(&self, mut cfg: OpenCfg) -> io::Result<Option<std::process::ExitStatus>> {
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)
}
Expand Down
7 changes: 5 additions & 2 deletions src/note/task_items_term_tree.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
))
Expand Down

0 comments on commit 51f3e0b

Please sign in to comment.