dot

packages and services management
Log | Files | Refs | README

commit f99c6c1c9a759f23199e4be6cbe07d5df0c7f3e9
parent 12b6d700e6f5f3f2daf5d132d3dfbeb29a91913f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Fri, 16 Mar 2018 01:29:48 +0100

updated comments

Diffstat:
Mbin/lstree | 23++++++++++++-----------
Mbin/pstree | 42++++++++++++++++++++++++++++++++++++++----
Mbin/xdg-open | 1+
3 files changed, 51 insertions(+), 15 deletions(-)

diff --git a/bin/lstree b/bin/lstree @@ -2,11 +2,8 @@ # list paths in a tree with some stat infos -# find(1) walk the entire tree and then ({} + means call at the end) call -# ls -ld with all the result, which are then sorted. The result will be -# a list with all ls -l information and the the path name from the current -# directory (./). This pattern is used to delimit the find-style output, -# which is transformed into tree(1)-style output: +# Use find(1) walk the entire tree and then call ls -ld with all the +# result (ls sort the list itself) with the paths displayed as a tree: # # drwxr-xr-x 2 josuah josuah 512 Feb 16 13:19 |- .ssh # -rw-r--r-- 1 josuah josuah 870 Feb 9 02:24 | `- config @@ -33,11 +30,11 @@ BEGIN { } # 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: +# holding the component j of the path i, and 0 has all the -l details, +# then return the number of entries in entries[]. # # [ 1:[ 0:"-rw-r--r-- 1 root root 341 Mar 13 10:50", -# 1:"etc", -# 2:"passwd" ], +# 1:"etc" ], # 2:[ 0:"drwxr-xr-x 28 root root 4096 Mar 13 10:50", # 1:"etc", # 2:"sv" ], @@ -45,7 +42,10 @@ BEGIN { # 1:"etc", # 2:"tor" ] ] # -# Then return the number of entries in entries[]. +# 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" ] ] function list(entries, path) { @@ -74,8 +74,9 @@ function list(entries, path) return num - 1; } -# Transform entries into a tree with duplicated components replaced by -# a line for drawing a tree. +# 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. function tree(entries, num) { diff --git a/bin/pstree b/bin/pstree @@ -2,6 +2,23 @@ # pstree implementation in awk +# Use ps(1) to generate a list of pid, ppid and other properties with +# the command name, displayed as a tree built from the pid-ppid pairs: +# +# USER TT NI PID STAT COMMAND +# root ? 0 1 Ss runit +# josuah ? 0 22437 S |- startx +# josuah ? 0 22451 S | `- xinit +# root tty7 0 22452 Rsl+ | |- Xorg +# josuah ? 0 22457 S | `- dwm +# josuah ? 0 24882 S `- runsvdir +# josuah ? 0 24884 S |- runsv +# josuah ? 0 24887 S | |- svlogd +# josuah ? 0 24890 S | `- ratox +# josuah ? 0 24885 S `- runsv +# josuah ? 0 24405 S |- tor +# josuah ? 0 24889 S `- svlogd + BEGIN { LINE = "| "; NODE = "|- "; @@ -20,7 +37,11 @@ BEGIN { } } -# Build a relational database in entries from the output of ps. +# Build a relational database in entries from the output of ps: The +# parent pid (ppid) -> pid pairs are used to accumulate a list of child +# pid (serialized into a csv: ",234,532,454"). +# +# For each pid, "info" and "comm" are saved as well. function list(entries) { @@ -48,7 +69,19 @@ function list(entries) } # Using the informations from the child pid in entries, build the absolute -# path from PID 1 to every pid. +# path from PID 1 to each pid: +# +# [ 1:[ 1:"1" ], +# 2:[ 1:"1", 2:"456" ], +# 3:[ 1:"1", 2:"456", 3:"1623" ], +# 4:[ 1:"1", 2:"456", 3:"1721" ] ] +# +# With also ":info" and ":comm" for every row. +# +# 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" ] ] function fill(entries, pid, lvl) { @@ -65,8 +98,9 @@ function fill(entries, pid, lvl) } } -# Transform entries into a tree with duplicated components replaced by -# a line for drawing a tree. +# 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. function tree(entries, num) { diff --git a/bin/xdg-open b/bin/xdg-open @@ -133,6 +133,7 @@ case "$1" in if [ "$file" ] then printf '/%s\r\n' "$path" | nc "$host" + exit else exec sacc "$1" fi