summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2020-06-01 16:26:15 +0200
committerCanop <cano.petrole@gmail.com>2020-06-01 16:26:15 +0200
commit796cb6cb955b96dcfda5d2310169b82ab6ba6d65 (patch)
treeea7a6a3cc38f46040fb1a88ae0b7ceeb1e251ed0
parent928365ae4bf4370b6bed57de1488d347fc5cc644 (diff)
`apply_to` verb property
Fix #237
-rw-r--r--CHANGELOG.md4
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/command/event.rs23
-rw-r--r--src/conf.rs13
-rw-r--r--src/verb/verb_conf.rs12
-rw-r--r--website/docs/conf_file.md14
-rw-r--r--website/docs/tricks.md19
8 files changed, 64 insertions, 25 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ccc5f48..b5e32a8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+<a name="v0.14.2"></a>
+### v0.14.2 - 2020-06-01
+- `apply_to` verb property - fix #237
+
<a name="v0.14.1"></a>
### v0.14.1 - 2020-05-29
- fix uppercase letters ignored in input field
diff --git a/Cargo.lock b/Cargo.lock
index a56dce8..7671ca3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -93,7 +93,7 @@ dependencies = [
[[package]]
name = "broot"
-version = "0.14.1"
+version = "0.14.2"
dependencies = [
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 8954a15..80ffd8b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "broot"
-version = "0.14.1"
+version = "0.14.2"
authors = ["dystroy <denys.seguret@gmail.com>"]
repository = "https://github.com/Canop/broot"
documentation = "https://dystroy.org/broot"
diff --git a/src/command/event.rs b/src/command/event.rs
index b504382..819760a 100644
--- a/src/command/event.rs
+++ b/src/command/event.rs
@@ -171,17 +171,20 @@ impl PanelInput {
};
}
-
// we now check if the key is the trigger key of one of the verbs
- if let Some(index) = con.verb_store.index_of_key(key) {
- let selection_type = state.selection_type();
- if selection_type.respects(con.verb_store.verbs[index].selection_condition) {
- return Command::VerbTrigger {
- index,
- input_invocation: parts.verb_invocation,
- };
- } else {
- debug!("verb not allowed on current selection");
+ let selection_type = state.selection_type();
+ for (index, verb) in con.verb_store.verbs.iter().enumerate() {
+ for verb_key in &verb.keys {
+ if *verb_key == key {
+ if selection_type.respects(verb.selection_condition) {
+ return Command::VerbTrigger {
+ index,
+ input_invocation: parts.verb_invocation,
+ };
+ } else {
+ debug!("verb not allowed on current selection");
+ }
+ }
}
}
diff --git a/src/conf.rs b/src/conf.rs
index 80f6474..981a86e 100644
--- a/src/conf.rs
+++ b/src/conf.rs
@@ -5,6 +5,7 @@ use {
crate::{
errors::ConfError,
keys,
+ selection_type::SelectionType,
skin::SkinEntry,
tree::*,
verb::VerbConf,
@@ -147,6 +148,17 @@ impl Conf {
);
continue;
}
+ let selection_condition = match string_field(verb_value, "apply_to").as_deref() {
+ Some("file") => SelectionType::File,
+ Some("directory") => SelectionType::Directory,
+ Some("any") => SelectionType::Any,
+ None => SelectionType::Any,
+ Some(s) => {
+ eprintln!("Invalid [[verbs]] entry in configuration");
+ eprintln!("{:?} isn't a valid value of apply_to", s);
+ continue;
+ }
+ };
let verb_conf = VerbConf {
invocation,
execution,
@@ -155,6 +167,7 @@ impl Conf {
description: string_field(verb_value, "description"),
from_shell,
leave_broot,
+ selection_condition,
};
self.verbs.push(verb_conf);
diff --git a/src/verb/verb_conf.rs b/src/verb/verb_conf.rs
index c753d05..a954ae1 100644
--- a/src/verb/verb_conf.rs
+++ b/src/verb/verb_conf.rs
@@ -1,4 +1,12 @@
-use {super::*, crate::errors::ConfError, crossterm::event::KeyEvent, std::convert::TryFrom};
+use {
+ super::*,
+ crate::{
+ errors::ConfError,
+ selection_type::SelectionType,
+ },
+ crossterm::event::KeyEvent,
+ std::convert::TryFrom,
+};
/// what's needed to handle a verb
#[derive(Debug)]
@@ -10,6 +18,7 @@ pub struct VerbConf {
pub description: Option<String>,
pub from_shell: Option<bool>,
pub leave_broot: Option<bool>,
+ pub selection_condition: SelectionType,
}
impl TryFrom<&VerbConf> for Verb {
@@ -54,6 +63,7 @@ impl TryFrom<&VerbConf> for Verb {
if let Some(description) = &verb_conf.description {
verb.description = VerbDescription::from_text(description.to_string());
}
+ verb.selection_condition = verb_conf.selection_condition;
Ok(verb)
}
}
diff --git a/website/docs/conf_file.md b/website/docs/conf_file.md
index 982d222..4a5f5f3 100644
--- a/website/docs/conf_file.md
+++ b/website/docs/conf_file.md
@@ -57,11 +57,14 @@ Be careful that those paths (globs, in fact) are checked a lot when broot builds
You can define a new verb in the TOML configuration file with a `[[verbs]]` section similar to this one:
- [[verbs]]
- invocation = "edit"
- key = "F2"
- shortcut = "e"
- execution = "/usr/bin/nvim {file}"
+```toml
+[[verbs]]
+invocation = "edit"
+key = "F2"
+shortcut = "e"
+apply_to = "file"
+execution = "/usr/bin/nvim {file}"
+```
The possible attributes are:
@@ -73,6 +76,7 @@ key | no | a keyboard key triggerring execution
shorcut | no | an alternate way to call the verb (without the arguments part)
leave_broot | no | whether to quit broot on execution (default: `true`)
from_shell | no | whether the verb must be executed from the parent shell (needs `br`, default: `false`). As this is executed after broot closed, this isn't compatiple with `leave_broot = false`
+apply_to | no | the type of selection this verb applies to, may be `"file"`, `"directory"` or `"any"`. You may declare two verbs with the same key if the first one applies to only files or only directories
!!! Note
The `from_shell` attribute exists because some actions can't possibly be useful from a subshell. For example `cd` is a shell builtin which must be executed in the parent shell.
diff --git a/website/docs/tricks.md b/website/docs/tricks.md
index dfc9d59..4308166 100644
--- a/website/docs/tricks.md
+++ b/website/docs/tricks.md
@@ -46,16 +46,21 @@ Or if you realize you want to match `tOo` too, then you make it case insensitive
If your system is normally configured, just doing `alt`-`enter` on an executable will close broot and executes the file.
-## Open files without a windowing system
+## Change standard file opening
-If you're on a server linux without xdg-open or equivalent, you may want to redefine the way broot open files on `enter`.
+When you hit enter on a file, broot asks the system to open the file. It's usually OK but you might wish to change that, for example when you're on a server without xdg-open or equivalent.
-You may use such configuration:
+Here's an example of configuration changing the behaviour on open:
- [[verbs]]
- invocation = "edit"
- key = "enter"
- execution = "$EDITOR {file}"
+```toml
+[[verbs]]
+invocation = "edit"
+key = "enter"
+execution = "$EDITOR {file}"
+apply_to = "file"
+```
+
+(the `apply_to` line ensures this verb isn't called when the selected line is a directory)
## Git Status