treeコマンドの改良版であるtreを試してみた
はじめに
tree
コマンドの改良版であるtreを使用してみました.
treはRust製のツールで,tree
をより使いやすくしたものです.
ツリー構造をカラー表示してくれるだけでなく,ファイルやディレクトリの横に表示されている番号を指定することで,
自身が使用しているエディターでそのファイルを開くことも可能です.
treの使い方や設定方法について,こちらにメモを残しておきます.
最近ターミナルの改造にハマっており,その他のツールについてもまとめておりますので,良ければご参照ください.
treとは
treとは,Rust製のツールでtree
をより使いやすくしたものです.
ツリー構造をカラー表示したり,ファイル横の番号を指定することで,
自身が使用しているエディターでそのファイルを開くことも可能です.
インストール方法
Macを使用している場合はHomebrewで,Rustの環境がある場合はcargoでインストールが可能です.
その他のインストール方法に関してはこちらをご参照ください.
brew install tre-command
# or
cargo install tre-command
インストールが完了したら,使用しているシェルの設定ファイル(.zshrc
, .bashrc
など)に以下を書き込みます.
tre() { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
こちらを設定すると,ツリー構造に表示されたファイルの番号を指定することで,そのファイルをエディタで開けるようになります.
デフォルトでは$EDITOR
に指定されているエディタを使用します.
$EDITOR
を設定していない場合は,-e
の後ろに使用するエディタを指定することも可能です.
tre() { command tre "$@" -e vim && source "/tmp/tre_aliases_$USER" 2>/dev/null; }
使い方
tre
コマンドを実行することで,ディレクトリのツリー構造を可視化することができます.
その後に特定のファイルをエディタで開きたい場合は,e<ファイル番号>
を実行します.
上記の画像のように,ディレクトリ構造を綺麗に可視化しつつ,簡単にファイルを開くことができます!
オプションに関しては以下を確認ください.
~ tre --help Usage: tre [path] [option] Print files, directories, and symlinks in tree form. Hidden files and those configured to be ignored by git will be (optionally) ignored. With correct configuration, each displayed file can have a shell alias created for it, which opens the file in the default editor or an otherwise specified command. Path: The root path whose content is to be listed. Defaults to ".". Options: -a, --all Print all files and directories, including hidden ones. -d, --directories Only list directories in output. -e, --editor [EDITOR] Create aliases for each displayed result in /tmp/tre_aliases_$USER and add a number in front of file name to indicate the alias name. For example, a number "42" means an shell alias "e42" has been created. Running "e42" will cause the associated file or directory to be open with $EDITOR, or a command specified along with this command. -j, --json Output JSON instead of tree diagram. -l, --limit [DEPTH] Limit display depth file tree output. -s, --simple Use normal print despite gitignore settings. '-a' has higher priority. -v, --version Show version number. -h, --help Show this help message. Project site: https://github.com/dduan/tre