Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make open_cmd configurable #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
make open-cmd (default: xdg-open) configurable
  • Loading branch information
gauteh committed Mar 31, 2020
commit 48b102e709191270b604a773a5656086d9bd0c15
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct Config {
pub show_hidden: bool,
pub select_cmd: String,
pub cd_cmd: String,
pub open_cmd: String,
pub icons: bool,
pub icons_space: bool,
pub media_autoplay: bool,
Expand All @@ -113,6 +114,7 @@ impl Config {
show_hidden: false,
select_cmd: "find -type f | fzf -m".to_string(),
cd_cmd: "find -type d | fzf".to_string(),
open_cmd: "xdg-open".to_string(),
icons: false,
icons_space: false,
media_autoplay: false,
Expand Down Expand Up @@ -158,6 +160,10 @@ impl Config {
let cmd = cmd.to_string();
config.cd_cmd = cmd;
}
Ok(("open_cmd", cmd)) => {
let cmd = cmd.to_string();
config.open_cmd = cmd;
}
Ok(("media_autoplay", "on")) => config.media_autoplay = true,
Ok(("media_autoplay", "off")) => config.media_autoplay = false,
Ok(("media_mute", "on")) => config.media_mute = true,
Expand Down
12 changes: 9 additions & 3 deletions src/file_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,13 @@ impl FileBrowser {
self.core.get_sender().send(Events::InputEnabled(false))?;
self.core.screen.suspend().log();

let status = std::process::Command::new("xdg-open")
let cmd = self.core
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the calls to clone here. If it complains about lifetimes you can do it like this:

let config = self.core
                .config.read()?
                .get()?;

Command::new(&config.open_cmd)

.config.read()?
.get()?
.open_cmd
.clone();

let status = std::process::Command::new(cmd.clone())
.args(file.path.file_name())
.status();

Expand All @@ -397,10 +403,10 @@ impl FileBrowser {
match status {
Ok(status) =>
self.core.show_status(&format!("\"{}\" exited with {}",
"xdg-open", status)).log(),
cmd, status)).log(),
Err(err) =>
self.core.show_status(&format!("Can't run this \"{}\": {}",
"xdg-open", err)).log()
cmd, err)).log()
}
}

Expand Down