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:

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:

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:

I like running all of these flags together: br -s -p -d -f.

Running “br -s -p -d -f” to display size, permissions, date and only directories.

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

More from Linuxhit

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.