-
Notifications
You must be signed in to change notification settings - Fork 1
/
ncduz
executable file
·92 lines (84 loc) · 2.09 KB
/
ncduz
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/bash
# (C) NORCE Climate
# Tyge Løvset, Feb. 2020
__cleanup()
{
if [ -f $FILE.tmp ]; then
rm $FILE.tmp
echo Removed temp file.
fi
}
trap __cleanup EXIT
DEFAULT=index
FILE=$DEFAULT.ncdu.gz
CREATE=0
IMPORT=0
SCAN=0
HELP=0
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-z|--gzfile)
FILE="$2"
shift # past argument
shift # past value
;;
-i|--import)
IMPORT=1
shift # past argument
;;
-s|--save)
CREATE=1
shift # past argument
;;
-S)
CREATE=2
shift # past argument
;;
-m|--memory)
SCAN=1
shift # past argument
;;
-h|--help)
HELP=1
POSITIONAL+=("$1") # pass it through
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ $HELP == 1 ]; then
echo "`basename $0` {-i|-s|-S|-m} [-z indexfile]"
echo " -h, --help This help"
echo " -z file, --gzfile file Gzipped file index. Default $DEFAULT.ncdu.gz"
echo " -i, --import Import index file in ncdu2 (default mode)"
echo " -s, --save Scan folder tree, export new index file and quit"
echo " -S Scan folder tree, export new index, import it in ncdu2"
echo " -m, --memory Scan folder tree without saving index, open ncdu2"
echo ""
`dirname $0`/ncdu2 --help
elif [ $CREATE != 0 ]; then
`dirname $0`/ncdu2 -1 --exclude .snapshots -o- $* | gzip > $FILE.tmp
if [ -f $FILE.tmp ]; then
if [ $FILE == $DEFAULT.ncdu.gz ] && [ -f $FILE ]; then
mv $FILE $DEFAULT.prev.gz
fi
mv $FILE.tmp $FILE
if [ $CREATE == 2 ]; then
gzip -dc $FILE | `dirname $0`/ncdu2 -f- $*
fi
fi
elif [ $SCAN == 1 ]; then
`dirname $0`/ncdu2 --exclude .snapshots $*
elif [ -f $FILE ]; then
gzip -dc $FILE | `dirname $0`/ncdu2 -f- $*
else
echo " No index file '$FILE' to import."
echo " Create index file with -s, or -h for help."
fi