URI: 
       ltree - plstree - ps and ls displayed as a tree
  HTML git clone git://bitreich.org/plstree git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/plstree
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
       ---
       ltree (2739B)
       ---
            1 #!/usr/bin/awk -f
            2 
            3 # list paths in a tree with some stat infos
            4 
            5 # Use find(1) walk the entire tree and then call ls -ld with all the
            6 # result (ls sort the list itself) with the paths displayed as a tree:
            7 #
            8 #        drwxr-xr-x   2 josuah  josuah     512 Feb 16 13:19  ├─ .ssh
            9 #        -rw-r--r--   1 josuah  josuah     870 Feb  9 02:24  │  └─ config
           10 #        drwxr-xr-x   2 josuah  josuah    1536 Feb 18 21:24  ├─ bin
           11 #        -rwxr-xr-x   1 josuah  josuah    1351 Feb 18 22:30  │  ├─ lt
           12 #        -rwxr-xr-x   1 josuah  josuah     565 Feb 17 19:53  │  ├─ mfilter
           13 #        -rwxr-xr-x   1 josuah  josuah    5430 Feb 17 19:51  │  └─ xdg-open
           14 #        -rwxr-xr-x   1 josuah  josuah     468 Feb 17 19:55  ...
           15 
           16 BEGIN {
           17         LINE = "│  ";
           18         NODE = "├─ ";
           19         TAIL = "└─ ";
           20         VOID = "   ";
           21 
           22         num = list(entries, ARGC == 1 ? "." : ARGV[1]);
           23         tree(entries, num);
           24 
           25         for (l = 1; l <= num; l++) {
           26                 for (i = 1; entries[l":"i] != ""; i++)
           27                         printf("%s", entries[l":"i]);
           28                 printf("%s\n", entries[l"name"]);
           29         }
           30 }
           31 
           32 # Get a recursive list of all entries into entries[] with entries[i:j]
           33 # holding the component j of the path i, and 0 has all the -l details,
           34 # then return the number of entries in entries[].
           35 #
           36 #        [ 1:[ 0:"-rw-r--r-- 1  root root  341 Mar 13 10:50",
           37 #              1:"etc" ],
           38 #          2:[ 0:"drwxr-xr-x 28 root root 4096 Mar 13 10:50",
           39 #              1:"etc",
           40 #              2:"sv" ],
           41 #          3:[ 0:"drwxr-xr-x  2 root root 4096 Mar 13 10:50",
           42 #              1:"etc",
           43 #              2:"tor" ] ]
           44 #
           45 # Only the leaves are present, the intermediates components are LINE or
           46 # NODE if just before a leave
           47 #
           48 #        [ 1:[ 1:LINE, 2:LINE, 3:LINE, 4:LINE, 5:NODE, 6:"filename" ] ]
           49 
           50 function list(entries, path)
           51 {
           52         cmd = "cd '" path "' && exec find ."                                \
           53             " -name '*.git'        -prune -o"                                \
           54             " -name 'CVS'        -prune -o"                                \
           55             " -exec ls -ld {} +";
           56 
           57         for (num = 0; cmd | getline; num++) {
           58                 sub(" \\.$", "", $0);
           59                 sub(" -> .*", "", $0);
           60                 infos = $0;
           61                 sub(" \\./.*", "", infos);
           62                 sub(".* \\./", "./", $0);
           63 
           64                 entries[num"path"] = $0;
           65                 count = split($0, path_v, "/");
           66                 for (i = 2; i < count; i++)
           67                         entries[num":"i] = LINE;
           68 
           69                 entries[num":"count] = NODE;
           70                 entries[num":"1] = infos "  ";
           71                 entries[num"name"] = path_v[count];
           72         }
           73         close(cmd);
           74 
           75         return num - 1;
           76 }
           77 
           78 # Transform entries into a tree by replacing some LINE by VOID when needed.
           79 # The tree is walked from the bottom to the top, and column by column
           80 # toward the right until an empty column is met.
           81 
           82 function tree(entries, num)
           83 {
           84         for (i = 2; !stop; i++) {
           85                 stop = tail = 1;
           86                 for (l = num; l > 0; l--) {
           87                         if (entries[l":"i] == LINE && tail) {
           88                                 entries[l":"i] = VOID;
           89                                 stop = 0;
           90                         } else if (entries[l":"i] == NODE && tail) {
           91                                 entries[l":"i] = TAIL;
           92                                 tail = stop = 0;
           93                         } else if (!entries[l":"i]) {
           94                                 tail = 1;
           95                         }
           96                 }
           97         }
           98 }