broot – A new CLI tool
I am always amazed when a new useful CLI tool like broot is released. Using Linux for well over 20 years, I expect everything useful to be built already. From time to time a new tool comes out and I wonder “How did I live with out this?” Some examples of CLI tools that have changed my life:
- jq – command line JSON parser
- pv – pipe viewer, a tool for monitoring pipeline progress
- mosh – mobile shell
- socat – multipurpose relay
I expect I will be adding broot to the list. Check out the website here.
What is broot?
A CLI tool written in rust. You use it to explore and find directories. “I made broot to both replace the classical fuzzy finders and the old tree.” – Denys Séguret from his reddit post. So think of it as a combination of the tree and fzf commands.
The simplest use case is to launch it via the br
shell function and start typing the name of a directory. It does a fuzzy find showing all matching files in the tree. From within to the tool you can do all sorts of things.
Once launched, you can navigate and drill down into directories. You can edit files or open them with command configured for the given file type.
Installing broot
The broot website has installation instructions for various platforms. There are binaries for the following platforms:
- Windows 10+
- Linux
- Raspberry Pi (ARM) Linux
Simply download the binary and put into your $PATH
. I installed it in /usr/local/bin
.
If you are on OSX you can use Homebrew or MacPorts. Additionally if you have a rust development environment setup you can install the crate via cargo: cargo install broot
.
The first time you run broot it will prompt you to install a shell function br
. This is the intended way to run broot. Choosing “Yes” will install the shell function in .config/broot
in your home directory. It supports a few different shells. I run bash. On my system the function was installed at ~/.config/broot/launcher/bash/br
. Additionally my .bashrc
was updated to source the function: source /home/ken/.config/broot/launcher/bash/br
.
The br
function is a wrapper around the broot command:
# This script was automatically generated by the broot program
# 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"
}
If you change the configuration and want to restore it to the original state use the broot --install
command. Additionally you can print the shell function for a give shell using the --print-shell-function
flag. For example br --print-shell-function bash
.
Functionality
Some of the interesting options are:
-d
show last modified dates-h
show hidden files-f
only show directories-p
display permissions-s
show file an directory size
I like running all of these flags together: br -s -p -d -f
.
You can manipulate/move files. Copying, removing files and editing files. For example, to do the equivalent of rm -rf
on a directory, type space key and then rm
.Make sure have set in your $EDITOR
environment variable.
With the -g
or --gitignore
flag you can control if .gitignore
files are honored.
One command within broot that I find useful is the print_path
or pp
command.
Wish List
- Use broot like
ls
. For example, I want to runbr -p -d
to print a directory tree and immediately exit. Maybe I am missing something, but I have not found a way to do this. - Errors from verbs. For example, I get no feedback when the rm verb fails due to “permission denied”.
More from Linuxhit