Linuxメモ : Rust製のbrootでディレクトリツリーを探索
broot
Rust製のbroot
を使うとディレクトリツリー探索することができ、検索結果をエディタで開くなどの操作ができる。
インストール
README.mdのインストール方法によるとバイナリのダウンロードやcargo
でインストールできる。
$ cargo install broot
これでbroot
コマンドが使えるようになるが、broot
で検索したディレクトリにcd
できるようにするためにはbroot --install
を実行する。
$ broot --install You requested a clean (re)install. Removing /home/vagrant/.config/broot/launcher/refused. Writing br shell function in /home/vagrant/.local/share/broot/launcher/bash/1. Creating link from /home/vagrant/.config/broot/launcher/bash/br to /home/vagrant/.local/share/broot/launcher/bash/1. /home/vagrant/.bashrc successfully patched, you can make the function immediately available with source /home/vagrant/.bashrc /home/vagrant/.bash_profile successfully patched, you can make the function immediately available with source /home/vagrant/.bash_profile /home/vagrant/.zshrc successfully patched, you can make the function immediately available with source /home/vagrant/.zshrc The br function has been installed. You may have to restart your shell or source your shell init files. Afterwards, you should start broot with br in order to use its full power.
インストールが成功するとbr
でbroot
コマンドが実行できるようになる。
ヘルプメッセージ。
$ br --help broot 0.13.5 dystroy <denys.seguret@gmail.com> A tree explorer and a customizable launcher USAGE: broot [FLAGS] [OPTIONS] [root] FLAGS: -d, --dates Show the last modified date of files and directories -D, --no-dates Don't show last modified date -f, --only-folders Only show folders -F, --no-only-folders Show folders and files alike -g, --show-git-info Show git statuses on files and stats on repo -G, --no-show-git-info Don't show git statuses on files -h, --hidden Show hidden files -H, --no-hidden Don't show hidden files -i, --show-gitignored Show files which should be ignored according to git -I, --no-show-gitignored Don't show gitignored files -p, --permissions Show permissions, with owner and group -P, --no-permissions Don't show permissions -s, --sizes Show the size of files and directories -S, --no-sizes Don't show sizes -t, --trim-root Trim the root too and don't show a scrollbar -T, --no-trim-root Don't trim the root level, show a scrollbar --install Install or reinstall the br shell function --no-style Whether to remove all style and colors --help Prints help information -V, --version Prints version information OPTIONS: --outcmd <cmd-export-path> Where to write the produced cmd (if any) -c, --cmd <commands> Semicolon separated commands to execute --conf <conf> Semicolon separated paths to specific config files --height <height> Height (if you don't want to fill the screen or for file export) -o, --out <file-export-path> Where to write the produced path (if any) --set-install-state <state> Set the installation state (for use in install script) [possible values: undefined, refused, installed] --print-shell-function <shell> Print to stdout the br function for a given shell ARGS: <root> sets the root directory
使い方
br
に続けてディレクトリツリーを表示したいディレクトリを指定する。引数を指定しない場合はカレントディレクトリが表示される。
brootの画面では↑
, ↓
で行移動、ディレクトリに対してEnter
で子ディレクトリの展開ができる。
また、検索文字列を入力することができディレクトリ、ファイルに対してインクリメンタルサーチができる。
そして、検索結果のファイルを選択した状態で:e
を実行するとエディタで開くことができる。
:e
はエディタで開く操作だが、次で説明するように他にもいろいろな操作ができる。
実行可能な操作
実行可能な操作は?
キーを押して表示されるヘルプで確認できる。
例えば、:e
でファイルを編集できるし、:view
でページャで開ける。
また、:toggle_files
でディレクトリのみ表示に切り替え(コマンドラインオプションだと-f
)などオプション切り替えもできる。
パーミッション、更新日時表示
-p
オプションでパーミッション、-d
オプションで更新日時を表示できる。
サイズ表示
-s
オプションでどのディレクトリ、ファイルの容量が多いかを確認できる。
Gitステータス表示
-g
オプションでGitステータスを表示できる。