{"id":18997717,"url":"https://github.com/s0/tree.py","last_synced_at":"2025-04-22T14:24:40.263Z","repository":{"id":9838881,"uuid":"11829186","full_name":"s0/tree.py","owner":"s0","description":"Tree is a small utility that displays input from stdin in a tree-like structure","archived":false,"fork":false,"pushed_at":"2016-05-16T08:35:32.000Z","size":148,"stargazers_count":6,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-20T03:04:45.030Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-01T22:24:21.000Z","updated_at":"2022-06-09T00:31:19.000Z","dependencies_parsed_at":"2022-09-01T10:10:16.809Z","dependency_job_id":null,"html_url":"https://github.com/s0/tree.py","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0%2Ftree.py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0%2Ftree.py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0%2Ftree.py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s0%2Ftree.py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s0","download_url":"https://codeload.github.com/s0/tree.py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250256897,"owners_count":21400611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T17:42:16.577Z","updated_at":"2025-04-22T14:24:40.244Z","avatar_url":"https://github.com/s0.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"tree.py\n=======\n\n**tree.py** is a small utility that displays input from stdin in a tree-like\nstructure. It takes a large amount of inspiration from Steve Baker's original\nand widely deployed tree utility: http://mama.indstate.edu/users/ice/tree/\n\n**tree.py** operates in a very different way to the traditional **tree**\ncommand, it instead takes input from stdin (so you can pipe it data) and will\ntry and parse it and present it in an intuitive tree-like format.\n\n\n* [Usage](#usage)\n  * [Basic Usage](#basic-usage)\n  * [Usage with **find**](#usage-with-find-or-another-tool-with-similar-output)\n  * [Usage with **grep**](#usage-with-grep)\n* [Future Plans](#future-plans)\n* [Advanced Usage](#advanced-usage)\n  * [Notes](#notes)\n* [Copyright](#copyright)\n\n\n## Usage\n\n### Setup\n\nYou can put the file tree.py wherever you like, and set an alias in your\n`.bashrc` file if you use **bash**, or you can just copy it to your `/usr/bin/`\ndirectory:\n\n    \u003e sudo cp tree.py /usr/bin/\n\n### Basic Usage\n\nThe traditional way to use tree.py is with no commands (or with a path passed\nin as an argument) to display the whole directory tree of a target.\n\n    \u003e tree [path]\n\nFor Example:\n\n    \u003e tree ~/foo/bar\n\nBy default, files starting with a \"`.`\" are hidden, to include these files, you\ncan run tree.py with the `-a` flag, e.g:\n\n    \u003e tree -a ~/foo/bar\n\n### Usage with find *(or another tool with similar output)*\n\nTree automatically detects when data is being piped to it instead of standalone\nusage:\n\n    \u003e find . | tree\n\nExample Output:\n\n    .\n    ├── .git\n    │   └── ...\n    ├── COPYING\n    ├── DISCLAIMER\n    ├── README.md\n    └── tree.py\n\n    23 directories, 34 files\n\nYou can start to build up powerful commands that display in a nice tree-like\nway, for example, if you were to filter the above file names like so:\n\n    \u003e find . | grep head\n\nYou would get this result:\n\n    ./.git/logs/refs/heads\n    ./.git/logs/refs/heads/master\n    ./.git/refs/heads\n    ./.git/refs/heads/master\n\nAnd piped into tree.py...\n\n    \u003e find . | grep head | tree\n\n... it display like so:\n\n    .\n    └── .git\n        ├── logs\n        │   └── refs\n        │       └── heads\n        │           └── master\n        └── refs\n            └── heads\n                └── master\n\n    7 directories, 2 files\n\n### Usage with grep\n\nIf you are using grep to search for text within multiple files, tree.py can\nalso accept this input, and display a line-match count for each file. For this,\nas it is not *normal* input, you need to pass in `-i grep` or just `-i g`.\n\n    \u003e grep as ./COPYING ./DISCLAIMER | tree -i g\n\nResulting In:\n\n    .\n    ├── [2] COPYING\n    └── [1] DISCLAIMER\n\n    1 directory, 2 files\n\nAnd here's a nice example with xargs and find too:\n\n    \u003e find . -type f | xargs grep 'as' | tree -i g\n\nResulting In:\n\n    .\n    ├── .git\n    │   ├── [2] COMMIT_EDITMSG\n    │   ├── [1] HEAD\n    │   ├── [2] config\n    │   ├── hooks\n    │   │   ├── [1] commit-msg.sample\n    │   │   ├── [6] pre-commit.sample\n    │   │   ├── [2] pre-push.sample\n    │   │   ├── [42] pre-rebase.sample\n    │   │   ├── [3] prepare-commit-msg.sample\n    │   │   └── [3] update.sample\n    │   ├── [1] packed-refs\n    │   └── refs\n    │       └── remotes\n    │           └── origin\n    │               └── [1] HEAD\n    ├── [2] COPYING\n    ├── [1] DISCLAIMER\n    └── [18] tree.py\n\n    6 directories, 14 files\n\n\n## Future Plans\n\n\n* Implement tree for non-stdin usage (i.e. without needing `-i`)\n* More input file formats\n* Ability to display information on files such as file permissions, size, user,\ngroup, timestamps etc...\n\n\n## Advanced Usage\n\nThis is the help message that can be seen after running tree -h\n\n    \u003e tree -h\n\n    Usage: tree.py [-h]  [-i [none|normal|grep|g|n]] [other options ...] [target]\n\n    A small utility that displays input from stdin in a tree-like structure\n\n    -h, --help                 show the help message\n\n    -i, --mode, --input-mode   The input type. If ommitted, the default is\n                               \"auto\", if -i is given with no argument, then\n                               \"normal\" is used.\n\n                               Values:\n                                - auto:   (default when -i is not included in\n                                          the command)\n                                          automatically try and detect whether\n                                          data is being piped to tree, and if\n                                          so, use \"normal\" mode, otherwise use\n                                          \"none\" (checks if stdin is a tty)\n                                - none:   don't read from stdin, display a\n                                          target directory instead!\n                                - normal: [or n] (default when -i is included\n                                          but no value given)\n                                          Accept input which is one filename\n                                          per line\n                                - grep:   [or g] Accept input that is like grep\n                                          multi-file output (i.e. \"file: match\"\n                                          for each line, with single files\n                                          possibly appearing multiple times)\n\n    -c, --color, --colour      Use color in the tree.\n\n                               Values:\n                                - auto:   try and automatically detect\n                                - always\n                                - none\n\n    -a                         Include hidden files\n\n    -e, --encoding             Which characters should be used to draw the tree\n\n                               Values:\n                                - auto:   try and detect which would be best\n                                          (default)\n                                - utf-8\n                                - ascii\n\n\n### Notes\n\n**tree.py** *loosely* uses the environment variables `LS_COLORS` and\n`TREE_COLORS` to decide how to color the output. `TREE_COLORS` is given a\nhigher priority, overriding each individual 'match' in LS_COLORS. You can also\ndefine `count` and `bin` to set colours for when you pipe grep input into tree\nto colour the matches.\n\n\n## Copyright\n\nCopyright © 2013 Sam Lanning \u003csam@samlanning.com\u003e\n\nThis work is free. You can redistribute it and/or modify it under the terms of\nthe Do What The Fuck You Want To Public License, Version 2, as published by Sam\nHocevar. See the COPYING file for more details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs0%2Ftree.py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs0%2Ftree.py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs0%2Ftree.py/lists"}