Skip to content

Commit

Permalink
Restore edit_cmd and open_dir_cmd.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanChane committed Apr 14, 2024
1 parent 03185b4 commit 0baaffe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
4 changes: 2 additions & 2 deletions clashtui/src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ pub struct ClashTuiConfig {
pub clash_srv_name: String,
pub clash_srv_is_user: bool, // true: systemctl --user ...

pub edit_cmd: Option<String>,
pub open_dir_cmd: Option<String>,
pub edit_cmd: String,
pub open_dir_cmd: String,
}
impl ClashTuiConfig {
pub fn from_file(config_path: &str) -> Result<Self> {
Expand Down
19 changes: 8 additions & 11 deletions clashtui/src/utils/tui/impl_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,21 @@ impl ClashTuiUtil {
/// Exec `cmd` for given `path`
///
/// Auto detect `cmd` is_empty and use system default app to open `path`
fn spawn_open(cmd: Option<&String>, path: &Path) -> std::io::Result<()> {
fn spawn_open(cmd: &str, path: &Path) -> std::io::Result<()> {
use crate::utils::ipc::spawn;
match cmd {
Some(c) => {
let open_cmd = c.replace("%s", path.to_str().unwrap_or(""));
spawn("sh", vec!["-c", open_cmd.as_str()])
}
None => {
spawn("xdg-open", vec![path.to_str().unwrap_or("")])
}
if !cmd.is_empty() {
let open_cmd = cmd.replace("%s", path.to_str().unwrap_or(""));
return spawn("sh", vec!["-c", open_cmd.as_str()]);
} else {
return spawn("xdg-open", vec![path.to_str().unwrap_or("")]);
}
}

pub fn edit_file(&self, path: &Path) -> std::io::Result<()> {
Self::spawn_open(self.tui_cfg.edit_cmd.as_ref(), path)
Self::spawn_open(self.tui_cfg.edit_cmd.as_str(), path)
}
pub fn open_dir(&self, path: &Path) -> std::io::Result<()> {
Self::spawn_open(self.tui_cfg.open_dir_cmd.as_ref(), path)
Self::spawn_open(self.tui_cfg.open_dir_cmd.as_str(), path)
}
fn _update_state(
&self,
Expand Down

0 comments on commit 0baaffe

Please sign in to comment.