diff options
-rw-r--r-- | README.md | 45 | ||||
-rw-r--r-- | src/content_search/extensions.rs | 15 | ||||
-rw-r--r-- | src/content_search/needle.rs | 41 | ||||
-rw-r--r-- | website/docs/navigation.md | 1 |
4 files changed, 60 insertions, 42 deletions
@@ -46,7 +46,7 @@ Notice the *unlisted*? That's what makes it usable where the old `tree` command would produce pages of output. -`.gitignore` files are properly dealt with to put unwanted files out of your way (you can ignore them though, see [documentation](https://dystroy.org/broot/documentation/usage/#gitignore)). +`.gitignore` files are properly dealt with to put unwanted files out of your way (you can ignore them though, see [documentation](../navigation/#toggles)). ### Find a directory then `cd` to it @@ -59,38 +59,42 @@ broot is fast and never blocks, even when you make it search a big slow disk (an Most useful keys for this: * the letters of what you're looking for -* `<enter>` to select a directory (staying in broot) -* `<esc>` to get back to the previous state or clear your search -* `<alt><enter>` to get back to the shell having `cd` to the selected directory -* `:q` if you just want to quit (`<esc>`, or `<ctrl><q>` or `<ctrl><c>` work too) +* <kbd>enter</kbd> to select a directory (staying in broot) +* <kbd>esc</kbd> to get back to the previous state or clear your search +* <kbd>alt</kbd><kbd>enter</kbd> to get back to the shell having `cd` to the selected directory +* `:q` if you just want to quit (you can use <kbd>ctrl</kbd><kbd>q</kbd> if you prefer) ### Never lose track of file hierarchy while you search ![size](img/20191112-mycnf.png) -broot tries to select the most relevant file. You can still go from one match to another one using `<tab>` or arrow keys. +broot tries to select the most relevant file. You can still go from one match to another one using <kbd>tab</kbd> or arrow keys. -You may also search with a regular expression. To do this, add a `/` before or after the pattern. +You may also search with a regular expression. To do this, add a `/` before the pattern. + +And you have other types of searches, for example searching on file content (start with `c/`): + +![content search](website/docs/img/20200608-content-search.png) Once the file you want is selected you can -* hit `<enter>` (or double-click) to open it in your system's default program -* hit `<alt><enter>` to open it in your system's default program and close broot +* hit <kbd>enter</kbd> (or double-click) to open it in your system's default program +* hit <kbd>alt</kbd><kbd>enter</kbd> to open it in your system's default program and close broot * type a verb. For example `:e` opens the file in your preferred editor (which may be a terminal one) ### Manipulate your files ![mv](img/20191112-mv.png) -Without broot you move your files in the blind. You do a few `ls` before, then your manipulation, and maybe you check after. +Most often you move your files in the blind. You do a few `ls` before, then your manipulation, and maybe you check after. You can instead do it without losing the view of the file hierarchy. -`mv`, `cp`, `rm`, `mkdir`, are built in and you can add your own shortcuts. +Move, copy, rm, mkdir, are built in and you can add your own shortcuts. ### Do it with panels -Do `<ctrl><right>` and you open another panel (you may open other ones, or navigate between them, with `<ctrl><left>` and `<ctrl><right>`). +Do <kbd>ctrl</kbd><kbd>→</kbd> and you open another panel (you may open other ones, or navigate between them, with <kbd>ctrl</kbd><kbd>←</kbd> and <kbd>ctrl</kbd><kbd>→</kbd>). ![custom colors tree](website/docs/img/20200525-colored-panels.png) @@ -98,20 +102,19 @@ Do `<ctrl><right>` and you open another panel (you may open other ones, or navig Using two panels, you can for example copy or move elements between them: -![custom colors tree](website/docs/img/20200525-cpp.png) - -`:cpp` is an alias for `:copy_to_panel`. If you like you may do it Norton Commander style by binding `:copy_to_panel` to `<F5>` and `:move_to_panel` to `<F6>`. +![cpp](website/docs/img/20200525-cpp.png) +If you like you may do it Norton Commander style by binding `:copy_to_panel` to <kbd>F5</kbd> and `:move_to_panel` to <kbd>F6</kbd>. ### Apply a standard or personal shortcut to a file ![size](img/20191112-edit.png) -Just find the file you want to edit with a few keystrokes, type `:e`, then `<enter>`. +Just find the file you want to edit with a few keystrokes, type `:e`, then <kbd>enter</kbd>. -You can add verbs or configure the existing ones; see [documentation](https://dystroy.org/broot/documentation/usage/#verbs). +You can add verbs or configure the existing ones; see [documentation](documentation/usage.md#verbs). -And you can add shortcuts, for example a `ctrl` sequence or a function key +And you can add shorcuts, for example a <kbd>ctrl</kbd> sequence or a function key ### Replace `ls` (and its clones): @@ -119,9 +122,7 @@ If you want to display *dates* and *permissions*, do `br -dp` which gets you thi ![replace ls](img/20191214-replace-ls.png) -You may also toggle options with a few keystrokes while inside broot. For example hitting a space, a `d` then enter shows you the dates. - -You still have all broot features, you can filter, navigate, create directories, copy files, etc. +You may also toggle options with a few keystrokes while inside broot. For example hitting a space, a `d` then enter shows you the dates. Or a space, then `h` then enter and you see hidden files. ### See what takes space: @@ -139,5 +140,7 @@ Sizes are computed in the background, you don't have to wait for them when you n Use `:gf` to display the statuses of files (what are the new ones, the modified ones, etc.), the current branch name and the change statistics. +And if you want to see *only* the files which would be displayed by the `git status` command, do `:gs`. + ## Further Reading See **[Broot's web site](https://dystroy.org/broot)** for instructions regarding installation and usage. diff --git a/src/content_search/extensions.rs b/src/content_search/extensions.rs index 59f63bf..6d7eab5 100644 --- a/src/content_search/extensions.rs +++ b/src/content_search/extensions.rs @@ -5,15 +5,8 @@ /// If you feel this list should maybe be changed, contact /// me on miaou or raise an issue. pub fn is_known_binary(ext: &str) -> bool { - ext == "doc" - || ext == "iso" - || ext == "jpg" - || ext == "jpeg" - || ext == "ods" - || ext == "odt" - || ext == "pdf" - || ext == "png" - || ext == "ppt" - || ext == "rar" - || ext == "xls" + match ext { + "doc" | "iso" | "jpg" | "jpeg" | "ods" | "odt" | "pdf" | "png" | "ppt" | "rar" | "xls" => true, + _ => false, + } } diff --git a/src/content_search/needle.rs b/src/content_search/needle.rs index 6ad4a47..51795c6 100644 --- a/src/content_search/needle.rs +++ b/src/content_search/needle.rs @@ -58,6 +58,23 @@ impl Needle { hay.iter().position(|&b| b==n) } + fn find_naive_2(&self, mut pos: usize, hay: &Mmap) -> Option<usize> { + let max_pos = hay.len() - 2; + let b0 = self.bytes[0]; + let b1 = self.bytes[1]; + unsafe { + while pos <= max_pos { + if *hay.get_unchecked(pos) == b0 + && *hay.get_unchecked(pos+1) == b1 + { + return Some(pos); + } + pos += 1; + } + } + None + } + fn find_naive_3(&self, mut pos: usize, hay: &Mmap) -> Option<usize> { let max_pos = hay.len() - 3; let b0 = self.bytes[0]; @@ -141,6 +158,13 @@ impl Needle { /// search the mem map to find the first occurence of the needle. /// + /// Known limit: if the file has an encoding where the needle would + /// be represented in a way different than UTF-8, the needle won't + /// be found (I noticed the problem with other grepping tools, too, + /// which is understandable as detecting the encoding and translating + /// the needle would multiply the search time). + /// + /// /// The exact search algorithm used here (I removed Boyer-Moore) /// and the optimizations (loop unrolling, etc.) don't really matter /// as their impact is dwarfed by the whole mem map related set @@ -150,16 +174,13 @@ impl Needle { if hay.len() < self.bytes.len() { return ContentSearchResult::NotFound; } - let pos = if self.bytes.len() == 6 { - self.find_naive_6(0, &hay) - } else if self.bytes.len() == 4 { - self.find_naive_4(0, &hay) - } else if self.bytes.len() == 3 { - self.find_naive_3(0, &hay) - } else if self.bytes.len() == 1 { - self.find_naive_1(&hay) - } else { - self.find_naive(0, &hay) + let pos = match self.bytes.len() { + 1 => self.find_naive_1(&hay), + 2 => self.find_naive_2(0, &hay), + 3 => self.find_naive_3(0, &hay), + 4 => self.find_naive_4(0, &hay), + 6 => self.find_naive_6(0, &hay), + _ => self.find_naive(0, &hay), }; pos.map_or( ContentSearchResult::NotFound, diff --git a/website/docs/navigation.md b/website/docs/navigation.md index 3f5d9a3..d2237a1 100644 --- a/website/docs/navigation.md +++ b/website/docs/navigation.md @@ -9,6 +9,7 @@ The first line is called the root, and is currently selected. From here you may navigate using the following keys: * <kbd class=b>↓</kbd> or <kbd class=b>↑</kbd> : select the next or previous line +* <kbd class=b>←</kbd> or <kbd class=b>→</kbd> : focus (or open) a panel to the left or to the right * <kbd class=b>⏎</kbd> on a file : open the file using xdg-open (or your OS equivalent) * <kbd>alt</kbd> + <kbd class=b>⏎</kbd> on a file : leave broot and open the file using xdg-open * <kbd class=b>⏎</kbd> on a directory : focus the directory (i.e. make it the new root) |