diff --git a/Cargo.lock b/Cargo.lock index 9e0ee0d..50334cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,14 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + [[package]] name = "arrayref" version = "0.3.6" @@ -521,6 +530,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +[[package]] +name = "once_cell" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea78b9742c52ac729753c1590e9adc5248ea9bdaf974597efd46c74cfaa5fb54" + [[package]] name = "oorandom" version = "11.1.3" @@ -719,7 +734,10 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", + "thread_local", ] [[package]] @@ -859,6 +877,16 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "shellwords" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89e515aa4699a88148ed5ef96413ceef0048ce95b43fbc955a33bde0a70fcae6" +dependencies = [ + "lazy_static", + "regex", +] + [[package]] name = "signal-hook" version = "0.1.17" @@ -928,6 +956,15 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + [[package]] name = "tinytemplate" version = "1.2.0" @@ -1104,6 +1141,7 @@ dependencies = [ "handlebars", "serde", "serde_yaml", + "shellwords", "termion", "tui", ] diff --git a/Cargo.toml b/Cargo.toml index 1baab2e..2973e8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ dirs = "3.0.1" serde = { version = "1.0", features = ["derive"] } serde_yaml = "0.8" handlebars = "3.5.3" +shellwords = "1.0.0" [dev-dependencies] criterion = "0.3" diff --git a/src/config.rs b/src/config.rs index 5d8f5a6..f2c39f9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -224,16 +224,37 @@ impl Default for KeyBindings { help: open actions: - Call: - command: xdg-open + command: bash args: - - "{{absolutePath}}" + - "-c" + - "xdg-open {{shell_escape absolutePath}} x" + - Quit e: help: edit actions: - Call: command: vim args: - - "{{absolutePath}}" + - "{{absolutepath}}" + forward-slash: + help: search + actions: + - Call: + command: bash + args: + - "-c" + - "cd $(dirname {{shell_escape absolutePath}}) && fzf" + - Quit + + c: + help: copy to + actions: + - Call: + command: bash + args: + - "-c" + - "cp {{shell_escape absolutePath}} $(xplr)/" + escape: help: quit actions: diff --git a/src/main.rs b/src/main.rs index dfb567c..80dd6ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use crossterm::terminal as term; -use handlebars::Handlebars; +use handlebars::{handlebars_helper, Handlebars}; +use shellwords; use std::io; use termion::get_tty; use termion::{input::TermRead, screen::AlternateScreen}; @@ -11,10 +12,14 @@ use xplr::error::Error; use xplr::input::Key; use xplr::ui; +handlebars_helper!(hex: |v: i64| format!("0x{:x}", v)); +handlebars_helper!(shell_escape: |v: str| format!("{}", shellwords::escape(v))); + fn main() -> Result<(), Error> { let mut app = app::create()?; let mut hb = Handlebars::new(); + hb.register_helper("shell_escape", Box::new(shell_escape)); hb.register_template_string( app::TEMPLATE_TABLE_ROW, &app.config @@ -82,7 +87,9 @@ fn main() -> Result<(), Error> { let stdout = AlternateScreen::from(stdout); let backend = CrosstermBackend::new(stdout); terminal = Terminal::new(backend)?; - terminal.draw(|f| ui::draw(&a, &hb, f, &mut table_state, &mut list_state))?; + terminal.draw(|f| { + ui::draw(&a, &hb, f, &mut table_state, &mut list_state) + })?; }; a.call = None;