summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--img/20191214-replace-ls.pngbin0 -> 49776 bytes
-rw-r--r--src/conf.rs2
-rw-r--r--src/displayable_tree.rs48
-rw-r--r--src/flat_tree.rs40
-rw-r--r--src/shell_bash.rs40
-rw-r--r--src/shell_install/bash.rs2
-rw-r--r--website/docs/img/20191214-replace-ls.pngbin0 -> 49776 bytes
-rw-r--r--website/docs/index.md4
9 files changed, 99 insertions, 41 deletions
diff --git a/README.md b/README.md
index 3f1e592..a863083 100644
--- a/README.md
+++ b/README.md
@@ -76,6 +76,10 @@ You can add verbs or configure the existing ones; see [documentation](documentat
And you can add shorcuts, for example a `ctrl` sequence or a function key
+### Replace `ls` (and its clones):
+
+![replace ls](img/20191214-replace-ls.png)
+
### See what takes space:
![size](img/20191112-sizes.png)
diff --git a/img/20191214-replace-ls.png b/img/20191214-replace-ls.png
new file mode 100644
index 0000000..657968f
--- /dev/null
+++ b/img/20191214-replace-ls.png
Binary files differ
diff --git a/src/conf.rs b/src/conf.rs
index 0f98846..de8189e 100644
--- a/src/conf.rs
+++ b/src/conf.rs
@@ -6,7 +6,7 @@ use {
errors::ConfError,
skin_conf,
verb_conf::{self, VerbConf},
- }
+ },
crossterm::style::Attribute,
directories::ProjectDirs,
std::{
diff --git a/src/displayable_tree.rs b/src/displayable_tree.rs
index e27cb07..618522f 100644
--- a/src/displayable_tree.rs
+++ b/src/displayable_tree.rs
@@ -1,29 +1,29 @@
-use std::{time::SystemTime};
-
-#[cfg(unix)]
-use std::os::unix::fs::MetadataExt;
-
-use chrono::{offset::Local, DateTime};
-use crossterm::{
- cursor,
- queue,
- style::{Color, SetBackgroundColor},
- terminal::{Clear, ClearType},
-};
-use termimad::{
- CompoundStyle,
- ProgressBar,
+use {
+ crate::{
+ file_sizes::Size,
+ flat_tree::{LineType, Tree, TreeLine},
+ errors::ProgramError,
+ patterns::Pattern,
+ skin::Skin,
+ },
+ chrono::{offset::Local, DateTime},
+ crossterm::{
+ cursor,
+ queue,
+ style::{Color, SetBackgroundColor},
+ terminal::{Clear, ClearType},
+ },
+ std::{time::SystemTime},
+ termimad::{
+ CompoundStyle,
+ ProgressBar,
+ },
};
#[cfg(unix)]
-use crate::permissions;
-
-use crate::{
- file_sizes::Size,
- flat_tree::{LineType, Tree, TreeLine},
- errors::ProgramError,
- patterns::Pattern,
- skin::Skin,
+use {
+ crate::permissions,
+ std::os::unix::fs::MetadataExt,
};
/// A tree wrapper which can be used either
@@ -226,7 +226,7 @@ impl<'s, 't> DisplayableTree<'s, 't> {
}
}
if tree.options.show_dates && line_index > 0 {
- if let Ok(date) = line.metadata.modified() {
+ if let Some(date) = line.modified() {
self.write_date(f, date)?;
} else {
self.skin.tree.queue_str(f, "──────────────── ")?;
diff --git a/src/flat_tree.rs b/src/flat_tree.rs
index 8118821..f04d28c 100644
--- a/src/flat_tree.rs
+++ b/src/flat_tree.rs
@@ -1,10 +1,20 @@
/// In the flat_tree structure, every "node" is just a line, there's
/// no link from a child to its parent or from a parent to its children.
-use std::{
- cmp::{self, Ord, Ordering, PartialOrd},
- fs,
- mem,
- path::{Path, PathBuf},
+use {
+ crate::{
+ errors,
+ file_sizes::Size,
+ task_sync::TaskLifetime,
+ tree_build::TreeBuilder,
+ tree_options::TreeOptions,
+ },
+ std::{
+ cmp::{self, Ord, Ordering, PartialOrd},
+ fs,
+ mem,
+ path::{Path, PathBuf},
+ time::SystemTime,
+ },
};
#[cfg(unix)]
@@ -16,13 +26,6 @@ use {
#[cfg(windows)]
use is_executable::IsExecutable;
-use crate::{
- errors,
- file_sizes::Size,
- task_sync::TaskLifetime,
- tree_build::TreeBuilder,
- tree_options::TreeOptions,
-};
#[derive(Debug, Clone, PartialEq)]
pub enum LineType {
@@ -89,9 +92,9 @@ impl TreeLine {
#[cfg(windows)]
return self.path.is_executable();
}
- // build and return the absolute targeted path: either self.path or the
- // solved canonicalized symlink
- // (the path may be invalid if the symlink is)
+ /// build and return the absolute targeted path: either self.path or the
+ /// solved canonicalized symlink
+ /// (the path may be invalid if the symlink is)
pub fn target(&self) -> PathBuf {
match &self.line_type {
LineType::SymLinkToFile(target) | LineType::SymLinkToDir(target) => {
@@ -107,6 +110,13 @@ impl TreeLine {
_ => self.path.clone(),
}
}
+ /// return the last modification date, if it makes sense
+ pub fn modified(&self) -> Option<SystemTime> {
+ match &self.line_type {
+ LineType::Pruning => None,
+ _ => self.metadata.modified().ok(),
+ }
+ }
}
impl PartialEq for TreeLine {
fn eq(&self, other: &TreeLine) -> bool {
diff --git a/src/shell_bash.rs b/src/shell_bash.rs
new file mode 100644
index 0000000..5b3d7cc
--- /dev/null
+++ b/src/shell_bash.rs
@@ -0,0 +1,40 @@
+use crate::shell_install::ShellFamily;
+
+pub const BASH: ShellFamily<'static> = ShellFamily {
+ name: "bash",
+ sourcing_files: &[".bashrc", ".zshrc"],
+ version: 1,
+ script: BASH_FUNC,
+};
+
+// This script has been tested on bash and zsh.
+// It's installed under the bash name (~/.config/broot
+// but linked from both the .bashrc and the .zshrc files
+const BASH_FUNC: &str = r#"
+# This script was automatically generated by the broot function
+# More information can be found in https://github.com/Canop/broot
+
+# This function starts broot and executes the command
+# it produces, if any.
+# It's needed because some shell commands, like `cd`,
+# have no useful effect if executed in a subshell.
+function br {
+ f=$(mktemp)
+ (
+ set +e
+ broot --outcmd "$f" "$@"
+ code=$?
+ if [ "$code" != 0 ]; then
+ rm -f "$f"
+ exit "$code"
+ fi
+ )
+ code=$?
+ if [ "$code" != 0 ]; then
+ return "$code"
+ fi
+ d=$(<"$f")
+ rm -f "$f"
+ eval "$d"
+}
+"#;
diff --git a/src/shell_install/bash.rs b/src/shell_install/bash.rs
index 8463589..09274bc 100644
--- a/src/shell_install/bash.rs
+++ b/src/shell_install/bash.rs
@@ -58,7 +58,7 @@ function br {
if [ "$code" != 0 ]; then
return "$code"
fi
- d=$(cat "$f")
+ d=$(<"$f")
rm -f "$f"
eval "$d"
}
diff --git a/website/docs/img/20191214-replace-ls.png b/website/docs/img/20191214-replace-ls.png
new file mode 100644
index 0000000..657968f
--- /dev/null
+++ b/website/docs/img/20191214-replace-ls.png
Binary files differ
diff --git a/website/docs/index.md b/website/docs/index.md
index c43fce8..516a45c 100644
--- a/website/docs/index.md
+++ b/website/docs/index.md
@@ -64,6 +64,10 @@ You can add verbs or configure the existing ones; see [documentation](documentat
And you can add shorcuts, for example a `ctrl` sequence or a function key
+# Replace `ls` (and its clones):
+
+![replace ls](img/20191214-replace-ls.png)
+
# See what takes space:
![size](img/20191112-sizes.png)