dot

packages and services management
Log | Files | Refs | README

commit ecb8dffd4272316a1658fcff24a6761fe06ea908
parent 97d03433f91ba94fd5fc4cb3ba58b816958c917f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat,  7 Apr 2018 20:05:49 +0200

stand alone tree implementation

$ find | tree

Diffstat:
Mbin/epih | 2+-
Mbin/lstree | 4++--
Abin/tree | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mbin/xdg-open | 2+-
4 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/bin/epih b/bin/epih @@ -5,6 +5,6 @@ cat << EOF ** EPITECH PROJECT, 2017 ** $(basename "$(dirname "$(cd "$(git rev-parse --git-dir)"; pwd)")") ** File description: -** Copyright $(date +%Y) (c) Josuah Demangeon. All rights reserved. +** Copyright $(date +%Y) (c) Danny Boon. All rights reserved. */ EOF diff --git a/bin/lstree b/bin/lstree @@ -62,12 +62,12 @@ function list(entries, path) sub(".* \\./", "./", $0); count = split($0, path_v, "/"); - for (i = 2; i <= count; i++) + for (i = 2; i < count; i++) entries[num":"i] = LINE; entries[num":"count] = NODE; entries[num":"1] = infos " "; - entries[num"name"] = count == 1 ? "." : path_v[count]; + entries[num"name"] = path_v[count]; } close(cmd); diff --git a/bin/tree b/bin/tree @@ -0,0 +1,76 @@ +#!/usr/bin/awk -f + +# convert a list of paths into a tree + +BEGIN { + LINE = "| "; + NODE = "|- "; + TAIL = "`- "; + VOID = " "; + + num = list(entries); + tree(entries, num); + display(entries, num); +} + +# Get a recursive list of all entries into entries[] with entries[i:j] +# holding the component j of the path i, and 0 has all the -l details, +# then return the number of entries in entries[]. +# +# [ 1:[ 1:"etc" ], +# 2:[ 1:"etc", 2:"sv" ], +# 3:[ 1:"etc", 2:"tor" ] ] +# +# Only the leaves are present, the intermediates components are LINE or +# NODE if just before a leave +# +# [ 1:[ 1:LINE, 2:LINE, 3:LINE, 4:LINE, 5:NODE, 6:"filename" ], +# 2:[ 1:LINE, 2:LINE, 3:LINE, 4:NODE, 5:"filename" ] ] + +function list(entries) +{ + for (num = 0; getline; num++) { + sub("^/", "", $0); + sub("/$", "", $0); + count = split($0, nodelist, "/"); + for (i = 1; i < count; i++) + entries[num":"i] = LINE; + entries[num":"count] = NODE; + entries[num"name"] = nodelist[count]; + } + + return num - 1; +} + +# Transform entries into a tree by replacing some LINE by VOID when needed. +# The tree is walked from the bottom to the top, and column by column +# toward the right until an empty column is met which stops the algorithm. + +function tree(entries, num) +{ + for (i = 1; !stop; i++) { + stop = tail = 1; + for (l = num; l > 0; l--) { + if (entries[l":"i] == LINE && tail) { + entries[l":"i] = VOID; + stop = 0; + } else if (entries[l":"i] == NODE && tail) { + entries[l":"i] = TAIL; + tail = stop = 0; + } else if (!entries[l":"i]) { + tail = 1; + } + } + } +} + +# Print all entries line by line. + +function display(entries, num) +{ + for (l = 1; l <= num; l++) { + for (i = 1; entries[l":"i] != ""; i++) + printf("%s", entries[l":"i]); + printf("%s\n", entries[l"name"]); + } +} diff --git a/bin/xdg-open b/bin/xdg-open @@ -134,7 +134,7 @@ case "$1" in [ "$port" = . ] && port="" || port="-p $port" [ "$user" = . ] && user="" || user="$user@" [ "$pass" = . ] && pass="" || pass="$" - exec ssh $port "$user$host" + exec ssh -Y $port "$user$host" ;; (telnet://*) exec telnet "$port" "$host"