diff options
author | Canop <cano.petrole@gmail.com> | 2019-12-14 08:59:19 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2019-12-14 08:59:19 +0100 |
commit | d8ba179946ad10d777f93b4a280f00462a27d393 (patch) | |
tree | 2fd9686dc7445c2e0f1dd3700d6f022c88c04708 | |
parent | 94722132169e6d306bfbcbe19f8f1b4b8febed91 (diff) | |
parent | cd0b0dbb6bfa3e763a902ecf37a89b5692281b91 (diff) |
don't show dates on "unlisted"
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | img/20191214-replace-ls.png | bin | 0 -> 49776 bytes | |||
-rw-r--r-- | src/conf.rs | 2 | ||||
-rw-r--r-- | src/displayable_tree.rs | 48 | ||||
-rw-r--r-- | src/flat_tree.rs | 40 | ||||
-rw-r--r-- | src/shell_bash.rs | 40 | ||||
-rw-r--r-- | src/shell_install/bash.rs | 2 | ||||
-rw-r--r-- | website/docs/img/20191214-replace-ls.png | bin | 0 -> 49776 bytes | |||
-rw-r--r-- | website/docs/index.md | 4 |
9 files changed, 99 insertions, 41 deletions
@@ -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 Binary files differnew file mode 100644 index 0000000..657968f --- /dev/null +++ b/img/20191214-replace-ls.png 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 Binary files differnew file mode 100644 index 0000000..657968f --- /dev/null +++ b/website/docs/img/20191214-replace-ls.png 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) |