-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel-ncdu.sh
executable file
·76 lines (66 loc) · 2.13 KB
/
kernel-ncdu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
set -ue
declare -A paths
export paths
if [ $# -lt 1 ]; then
while read line; do
echo "$line t=$(date +%s%N)";
done < /dev/stdin
exit
fi
while read -r file time; do
time="$(echo "$time" | awk -F= '{print $2}')";
ctime="$(($time - ${lasttime-$time}))";
lasttime="$time";
file="$(realpath -m --relative-to=. "$file")"
while [ "x$file" != "x." ]; do
paths[$file]=$(($ctime+${paths[$file]-0}))
file="$(dirname "$file")"
done
done <<<$(grep "$1" -oe ' [^ ]* t=.*$' | grep -e '/')
function getpath() {
if [ "x$1" == "x." ]; then
for i in "${!paths[@]}"; do
echo "${paths[$i]} $i";
done | grep -e "^[^ ]* [^/]*$" | sort -rn
else
out="$(
for i in "${!paths[@]}"; do
echo "${paths[$i]} $i";
done | grep -e "^[^ ]* $1/[^/]*$" | sort -rn)"
if [ "x$out" == "x" ]; then
for i in "${!paths[@]}"; do
echo "${paths[$i]} $i";
done | grep -e "^[^ ]* $1$" | sort -rn
else
echo "$out"
fi
fi
}
function convertsecs() {
h=$(bc <<< "${1}/3600")
m=$(bc <<< "(${1}%3600)/60")
s=$(bc <<< "${1}%60")
printf "%02d:%02d:%05.2f\n" $h $m $s
}
function popdialog() {
selected="$1"
while [ "x$selected" != "x" ]; do
if [ "x$selected" != "x." ]; then
extra=".. ($(basename "$(dirname "$selected" | sed -e 's_^\.$_/_' -e 's/ //g')"))"
fi
newselected="$(dialog --stdout --menu "Kernel NCDU" 0 0 0 ${extra-} $(
while read -r ctime file; do
echo "$(basename "${file}")" "$(convertsecs "$(bc <<< "scale=10; ${ctime}/1000000000")")"
done <<<"$(getpath "$selected")"))"
if [ "x$selected" != "x." ] && [ "x$newselected" != "x.." ] && [ "x$newselected" != "x$(basename "$selected")" ]; then
selected="$selected/$newselected"
elif [ "x$newselected" == "x.." ] || [ "x$newselected" == "x$(basename "$selected")" ]; then
unset extra
selected="$(dirname "$selected")"
else
selected="$newselected"
fi
done
}
popdialog .