-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.bash
More file actions
68 lines (67 loc) · 981 Bytes
/
Copy pathscript.bash
File metadata and controls
68 lines (67 loc) · 981 Bytes
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
#!/bin/bash
export LANG=en_US.UTF-8
d=0
f=0
function print()
{
local subdirs=($1/*)
local subdir_count=${#subdirs[@]}
local c=$2
local flag=$3
for counter in ${!subdirs[@]}; do
if [ $flag -eq 0 ]
then
for ((i=0; i<c; i++)); do
echo -n "│ "
done
else
for ((i=1; i<c; i++)); do
echo -n "│ "
done
echo -n " "
fi
if [ $counter -eq $(($subdir_count-1)) ]
then
echo -n "└── "
else
echo -n "├── "
fi
echo ${subdirs[$counter]##*/}
if [ -d ${subdirs[$counter]} ]
then
((d++))
if [ $counter -eq $(($subdir_count-1)) ]
then
print ${subdirs[$counter]} $(($c+1)) 1
else
print ${subdirs[$counter]} $(($c+1)) 0
fi
elif [ -f ${subdirs[$counter]} ]
then
((f++))
fi
done
}
if [ -z "$1" ]
then
echo '.'
print '.' 0 0
else
echo $1
print $1 0 0
fi
printf '\n'
echo -n $d
if [ $d -eq 1 ]
then
echo -n " directory, "
else
echo -n " directories, "
fi
echo -n $f
if [ $f -eq 1 ]
then
echo " file"
else
echo " files"
fi