https://github.com/wevre/pptree
Clojure utility for displaying arbitrary filenames in an outline, like `tree` command.
https://github.com/wevre/pptree
Last synced: 6 days ago
JSON representation
Clojure utility for displaying arbitrary filenames in an outline, like `tree` command.
- Host: GitHub
- URL: https://github.com/wevre/pptree
- Owner: wevre
- License: epl-2.0
- Created: 2020-07-28T02:43:27.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-19T05:25:52.000Z (over 5 years ago)
- Last Synced: 2025-02-21T11:52:53.816Z (over 1 year ago)
- Language: Clojure
- Size: 37.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# pptree
A utility for creating a tree diagram (_à la_ unix `tree` command) for arbitrary
lists of filenames. By 'arbitrary', I mean that, unlike the `tree` command, you
don't have to list out all the files in a directory, you can print a tree for
the two or three files you care about, they can be from completely different
sub-directories, and they don't even need to _be_ real files, the input just
needs to be strings with separators that _look_ like files, and `pptree` will
sort them and display them in an outline showing the hierarchy.
# How to install
Clone the repository to your computer, change to its directory, and run the
following
```
mkdir classes
clj -e "(compile 'wevre.pptree.main)"
clj -A:uberjar
```
to make an executable jar file in 'target' directory of the project. If you
want, make an alias to that jar file so it can be invoked with `pptree` from the
command line. For example, in `~/.bashrc` place the following line
```
alias pptree='java -jar /target/pptree.jar'
```
# How to use
Assuming you created the executable jar file and alias as above, you could then
run the command with something like:
```
pptree
~/Documents/Important Files/file2.txt
~/Documents/Important Files/file10.txt
~/Documents/Important Files/file1.txt
^D
```
Note that the lines above indicate the following steps: typing 'pptree', hitting
return, typing three file names, hitting return after each one, and then typing
CTRL+D. This will run the `pptree` command and generate the following output:
```
~/Documents/Important Files/
├── file1.txt
├── file2.txt
└── file10.txt
```
Also, try running `pptree` using the contents of the sample test input and
trying out the various command line options, `-h`, `-l`, `-F`, `-f`, `-I`, for
example:
```
pptree -h < resources/test1.txt
```
To come full circle, you could _re-create_ the results of the tree command
(meaning you could get a tree printout of the current directory and
sub-directories -- the same thing that the `tree` command already does) with
something like this:
```
find "$PWD" -type f | pptree
```
which of course is completely pointless, except that when I did this in the
project directory, and scrolled through the (many screenfuls of) output, I was
happy to see that the natural sorting algorithm kicked in. For example, under
the `classes/` directory that Clojure creates, there are many files with a
number at the end of their name, and since `pptree` uses
[natural-compare](https://github.com/wevre/natural-compare) they were ordered
properly, unlike the `tree` command which sorts lexically (it has other sorting
options, but not natural sorting).
# Why did I create this?
At work I often send file locations to team members, and instead of just a list,
I wanted to be able to send something more visual that captured the hierarchy,
something like an outline, ...something like the `tree` command! But I didn't
want an entire directory like the `tree` command would give me, I wanted it to
work on a list of _arbitrary_ files (see opening paragraph), plus I was on
Windows and I didn't know if such a thing as the `tree` command even existed
(I've since learned that yes it does, but, still, _arbitrary_) so I decided to
write my own. My first version, which I still use at work, was in Python, and
then I later rewrote it in Clojure, which is what you are looking at now.
# How does it work?
Section to be written. Maybe I'll do a blog post or something, though I don't
currently have a blog. There are lots of problem spaces to explore with this
little project: parsing command-line options, recursion, using Clojure zippers
and tree walkers, lots of interesting stuff.
# License
Copyright © 2020 Mike Weaver
Licensed under the terms of the Eclipse Public License 2.0, see
[license.txt](https://github.com/wevre/pptree/blob/master/license.txt).