• Stars
    star
    757
  • Rank 59,989 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 5 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tree command, improved.

tre

A modern alternative to the tree command that:

  • lists directory structure in a tree-like diagram, like the classics.
  • skips ignored files in git repositories per .gitignore setting.
  • creates shell aliases for each listing that opens the files for you.
  • output in colors, respecting LS_COLORS settings when they exist.

Command aliasing demo:

Aliasing In Action

… in case you missed it: [8] is shown in front of "README.md" and typing e8 opened the file! See how to set this up.

Install

Via a package manager

Tre is available in the following package managers.

Manager / OS Command
Homebrew / macOS brew install tre-command
MacPorts / macOS port install tre-tree
Debian (testing) apt install tre-command
Scoop / Windows scoop install tre-command
Windows Package Manager winget install tre-command
Cargo cargo install tre-command
AUR / Arch Linux yay -S tre-command
pkgsrc / NetBSD 9.1+ pkgin install tre-command
Nixpkgs / NixOS Use tre-command
Nix flake Use github:dduan/tre

The commands above are basic instructions. Use your favorite alternatives if you have one. For example, use a config file for Nix; or other method to install from AUR; pkgsrc can be use on OSes other than NetBSD etc.

Pre-built executable

Choose an pre-built executable from the release page that fits your platform to download. Unpack it somewhere you'd like to run it from.

From Source

  1. Clone this repository: git clone https://github.com/dduan/tre.git.
  2. Ensure you have Rust and Cargo installed. If not, follow instruction here.
  3. In the root level of this repo, run cargo build --release.
  4. Move target/release/tre to somewhere in your PATH environment variable.

Editor aliasing

tre provides a -e flag that, when used, turns on the "editor aliasing" feature. Some shell configuration will make this work better.

macOS/Linux

By default, the environment variable $EDITOR is used as the editor. If a value following -e is supplied (tre -e emacs instead of tre -e), then the command specified by this value will be used instead of $EDITOR. Update the script in the next section accordingly.

Bash or Zsh

In ~/.bashrc or ~/.zshrc (for example)

tre() { command tre "$@" -e && source "/tmp/tre_aliases_$USER" 2>/dev/null; }

Fish

Create ~/.config/fish/functions/tre.fish:

function tre
  command tre $argv -e; and source /tmp/tre_aliases_$USER ^/dev/null
end

Windows (10+)

Instead of directly executing tre.exe, we'll set up a script that's available in your PATH environment variable. For example, you can add \Users\yourname\bin to your PATH environment variable, and created the script there. When you use tre, this script executes tre.exe, and do some additional work. The content of the script is different for PowerShell and Command Prompt.

By default, the default program known by Windows will be used to open the file. If a value following -e is supplied (tre -e notepad.exe instead of tre -e), then the command specified by this value will be used. Update the scripts in the next section accordingly.

PowerShell

Add a tre.ps1 file:

if (Get-Module PSReadLine) {
  Remove-Module -Force PSReadLine
}
tre.exe $args -e
. $Env:TEMP\tre_aliases_$env:USERNAME.ps1

Command Prompt (CMD.exe)

Add a tre.bat:

@echo off
tre.exe %* -e
call %TEMP%\tre_aliases_%USERNAME%.bat

How it works

The first thing you'll notice is some numbers in front of each file name in tre's output. If pick a number, say, "3", and enter e3 in the shell, the file after "3" will open in your default program (specified by the environment variable EDITOR in macOS/Linux, and picked by Windows).

Everytime tre runs with -e, it updates a file in a temporary directory, and adds an alias for each result it displays. And the additional configuration simply sources this file after the command. You can manually run

in Bash/Zsh/Fish:

source /tmp/tre_aliases_$USER

or

in PowerShell

. $Env:TEMP\tre_aliases_$env:USERNAME.ps1

or

in Command Prompt

call %TEMP%\tre_aliases_%USERNAME%.bat

… instead of configuring your system (if you are that patient!).

Everything else

Here's the output from tre -h, showing all available options provided by tre:

USAGE:
    tre [OPTIONS] [PATH]

ARGS:
    <PATH>    [default: .]

OPTIONS:
    -a, --all                   Print all files and directories, including hidden ones
    -c, --color <WHEN>          When to color the output. `automatic` means when printing to a
                                terminal, tre will include colors; otherwise it will disable colors
                                [default: automatic] [possible values: automatic, always, never]
    -d, --directories           Only list directories in output
    -e, --editor [<COMMAND>]    Create aliases for each displayed result, 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
                                default program for the file type on Windows), or a command
                                specified along with this command
    -E, --exclude <PATTERN>     Exclude paths matching a regex pattern. Repeatable
    -h, --help                  Print help information
    -j, --json                  Output JSON instead of tree diagram
    -l, --limit <LIMIT>         Limit depth of the tree in output
    -p, --portable              Generate portable (absolute) paths for editor aliases. By default,
                                aliases use relative paths for better performance
    -s, --simple                Use normal print despite gitignore settings. '-a' has higher
                                priority
    -V, --version               Print version information

If you like the editor aliasing feature, you may want to check out ea.

Packaging

tre is a standard Cargo-managed Rust project. A unix manual is available at manual/tre.1. Completion scripts for various shells are at scripts/completion.

License

MIT. See LICENSE.md.

More Repositories

1

Just

Swift HTTP for Humans
Swift
1,397
star
2

needless

A utility to find needless words in Swift function names.
Swift
175
star
3

DrString

DrString finds issues in your Swift docstrings and fixes them for you.
Swift
170
star
4

Pathos

File management and path analysis for Swift
Swift
110
star
5

Markra

An open-source Markdown-to-JIRA syntax editor written in SwiftUI for macOS
Swift
92
star
6

Termbox

Swift Wrapper for Termbox: A Lightweight TUI Library
C
66
star
7

TOMLDecoder

From TOML to Swift Codable types.
Swift
63
star
8

git2dayone

A script for logging git commit messages in the app Day One
Shell
39
star
9

DistributionTests

Swift 3 distribution test for open-source libraries.
Makefile
23
star
10

Swift-Framework-Without-Xcode

A sample project to demonstrate how to build and link to Swift frameworks dynamically without using Xcode.
Makefile
22
star
11

Lic

Easy, safe object slicing for Swift
Swift
21
star
12

Tweet-Importer-For-Day-One

Imports Tweet Archive To Day One
Python
21
star
13

dotfiles

Nix
20
star
14

Swipe-Away

An iOS 7 demo of user interaction with UIView achieved via UIDynamics.
Objective-C
17
star
15

cURLLook

Represent your NSURLRequest with a cURL command.
Swift
16
star
16

Comprehension

List Comprehension For Swift
Swift
16
star
17

django-sophie

Just another Django-based blog engine, that runs on GAE.
Python
14
star
18

Clue

Clue is a Swift library, and a command-line tool that finds symbol references in Swift projects.
Swift
14
star
19

ea

ea: make your CLI output actionable.
Rust
13
star
20

BrainAss

A Brainfuck to WebAssembly compiler written in Haskell
Haskell
9
star
21

TerminalPaint

A project that demonstrates how to build a TUI program in Swift
Swift
9
star
22

swift-system-extras

Swift System, battery included.
Swift
9
star
23

Dye

Cross-platform terminal styling for Swift command-line interface.
Swift
8
star
24

NetTime

RFC 3339 compliant date/time data types.
Swift
8
star
25

BitArray

A space-efficient bit array with RandomAccessCollection conformance in Swift.
Swift
5
star
26

Flapcopy

A Flappy Bird inspired HTML5 game.
CoffeeScript
5
star
27

Relay

Stateless alternatives to Combine.Subject
Swift
5
star
28

DrString.vim

Vim integration for DrString
Vim Script
4
star
29

TOMLDeserializer

Replaced by https://github.com/dduan/TOMLDecoder
Swift
4
star
30

IsTTY

Helps you decide whether your file is a terminal device.
Swift
4
star
31

CoverMaker

A small macOS that generates YouTube video thumbnails from metadata, built with SwiftUI and The Composable Architecture
Swift
4
star
32

Factorino

Swift
3
star
33

swift-system-exit

`exit` system call for Swift
Swift
2
star
34

Scmark

Thin, faithful, but Swift-y wrappers for cmark.
C
2
star
35

nixSwiftPM

Nix helper for SwiftPM
Nix
2
star
36

PEG

Parsing Expression Grammar implemented in Swift.
Swift
1
star
37

AllTheSwiftFiles

Fetch all popular Swift files from Github for language feature study
Python
1
star
38

scoop-bucket

Scoop (https://scoop.sh) apps.
1
star
39

herp

Help Extract Real Phrases: A CLI Utility.
Swift
1
star
40

mmm

A interactive CLI helper for manipulating files.
Rust
1
star
41

SwiftOnNix

Scripts for generating Nix expression for the Swift toolchain.
Nix
1
star