summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2019-01-12 20:17:47 +0100
committerCanop <cano.petrole@gmail.com>2019-01-12 20:17:47 +0100
commitcbddbc621c49b2596f3a048f55b505b6b5c4bd59 (patch)
tree021db303518cbe5bbd1af9bccc42dc0b68ff6e98
parent77ac36719ed908a6a80bdc8966bfafde8cfdf6dd (diff)
fix configured verbs not correctly handling paths with spacesv0.4.6
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/external.rs10
-rw-r--r--src/main.rs2
-rw-r--r--src/verbs.rs25
5 files changed, 17 insertions, 24 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5af61fe..f5bba1b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -31,7 +31,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "broot"
-version = "0.4.5"
+version = "0.4.6"
dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"custom_error 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index d720002..aa5774e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "broot"
-version = "0.4.5"
+version = "0.4.6"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/broot"
description = "Fuzzy Search + tree + cd"
diff --git a/src/external.rs b/src/external.rs
index 064157b..26bf349 100644
--- a/src/external.rs
+++ b/src/external.rs
@@ -13,14 +13,14 @@ pub struct Launchable {
impl Launchable {
pub fn opener(path: &PathBuf) -> io::Result<Launchable> {
- Launchable::from(&format!("xdg-open {}", &path.to_string_lossy()))
+ Launchable::from(vec!["xdg-open".to_string(), path.to_string_lossy().to_string()])
}
- pub fn from(launch_string: &str) -> io::Result<Launchable> {
- let mut tokens = launch_string.split_whitespace().map(|t| t.to_string());
- match tokens.next() {
+ pub fn from(mut parts: Vec<String>) -> io::Result<Launchable> {
+ let mut parts = parts.drain(0..);
+ match parts.next() {
Some(exe) => Ok(Launchable {
exe,
- args: tokens.collect(),
+ args: parts.collect(),
just_print: false,
}),
None => Err(io::Error::new(io::ErrorKind::Other, "Empty launch string")),
diff --git a/src/main.rs b/src/main.rs
index 18a069b..4e9f5d4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -45,7 +45,7 @@ use crate::task_sync::TaskLifetime;
use crate::tree_options::TreeOptions;
use crate::verbs::VerbStore;
-const VERSION: &str = "0.4.5";
+const VERSION: &str = "0.4.6";
fn get_cli_args<'a>() -> clap::ArgMatches<'a> {
clap::App::new("broot")
diff --git a/src/verbs.rs b/src/verbs.rs
index bfad4e7..2b5a27f 100644
--- a/src/verbs.rs
+++ b/src/verbs.rs
@@ -1,6 +1,3 @@
-use lazy_static::lazy_static;
-use regex::{Captures, Regex};
-use std::borrow::Cow;
use std::collections::HashMap;
use std::fs::OpenOptions;
use std::io::{self, Write};
@@ -122,7 +119,7 @@ impl VerbExecutor for BrowserState {
} else {
// no output path provided. We write on stdout, but we must
// do it after app closing to have the normal terminal
- let mut launchable = Launchable::from(&path.to_string_lossy())?;
+ let mut launchable = Launchable::from(vec![path.to_string_lossy().to_string()])?;
launchable.just_print = true;
AppStateCmdResult::Launch(launchable)
}
@@ -141,24 +138,20 @@ impl VerbExecutor for BrowserState {
None => AppStateCmdResult::DisplayError("no parent found".to_string()),
},
":quit" => AppStateCmdResult::Quit,
- _ => AppStateCmdResult::Launch(Launchable::from(&verb.exec_string(path))?),
+ _ => AppStateCmdResult::Launch(Launchable::from(verb.exec_token(path))?),
})
}
}
impl Verb {
fn exec_string(&self, path: &Path) -> String {
- lazy_static! {
- static ref regex: Regex = Regex::new(r"\{([\w.]+)\}").unwrap();
- }
- regex
- .replace_all(&*self.exec_pattern, |caps: &Captures<'_>| {
- match caps.get(1).unwrap().as_str() {
- "file" => path.to_string_lossy(),
- _ => Cow::from("-hu?-"),
- }
- })
- .to_string()
+ self.exec_token(path).join(" ")
+ }
+ fn exec_token(&self, path: &Path) -> Vec<String> {
+ self.exec_pattern
+ .split_whitespace()
+ .map(|t| if t=="{file}" { path.to_string_lossy().to_string() } else { t.to_string() })
+ .collect()
}
pub fn description_for(&self, state: &BrowserState) -> String {
let line = match &state.filtered_tree {