/indent-filter-for-tree

Filter for tree command. It can indent without using indentation line.

Primary LanguagePythonMIT LicenseMIT

indent filter for tree

What it is?

filter for tree command.
can indent directories and files without using indentation line.
for linux ( filter.sh ) and windows ( filter.ps1 ).

for Linux

Prerequisites

  • jq
  • python3.x

Usage

tree [${TARGET_DIRECTORY}] -J | ./filter.sh

example

tree command only

$ tree ./directory0
./directory0
├── directory1
│   ├── directory2
│   │   ├── directory3
│   │   └── file3
│   └── file2
└── file1

tree commnad with filter

$ tree ./directory0 -J | ./filter.sh
./directory0/
        directory1/
                directory2/
                        directory3/
                        file3
                file2
        file1
$

for Windows

Prerequisites

  • Windows Powershell

Usage

create filter (see filter.ps1.)

PS C:\test> filter IndentFilter {
% { $_ -replace "^(.*[+,\\\\]-.*)$","$&\" } |
% { $_ -replace "\|   " ,"`t" }  |
% { $_ -replace "\+---" ,"`t" }  |
% { $_ -replace "\\---" ,"`t" }  |
% { $_ -replace "    "  ,"`t" }  |
% { If ( $_ -notmatch "`t+$" ){$_} }
}

use filter

tree /F /A [TARGET_DIRECTORY] | IndentFilter

example

tree command only

PS C:\test> tree .\directory0 /F /A
C:\TEST\DIRECTORY0
|   file1
|
\---directory1
    |   file2
    |
    \---directory2
        |   file3
        |
        \---directory3
PS C:\test>

tree commnad with filter

PS C:\test> tree .\directory0 /F /A | IndentFilter
C:\TEST\DIRECTORY0
        file1
        directory1\
                file2
                directory2\
                        file3
                        directory3\
PS C:\test>