-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path35-diskspace
executable file
·55 lines (49 loc) · 1.43 KB
/
35-diskspace
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
#!/data/data/com.termux/files/usr/bin/env zsh
# config
max_usage=90
alert_usage=75
bar_width=50
# colors
green="\e[1;32m"
red="\e[1;31m"
yellow="\e[1;33m"
BOLD='\033[1m'
NC='\033[0m'
# disk usage: ignore zfs, squashfs & tmpfs
# readarray -t dfs < <(df -H -t sdcardfs -t fuse -t fuse.rclone | tail -n+2)
dfs=("${(@f)$(df -H -t sdcardfs -t fuse -t fuse.rclone | tail -n+2)}")
printf "\n${BOLD}Disk Usage:${NC}\n"
for line in "${dfs[@]}"; do
# get disk usage
usage=$(echo "$line" | awk '{print $5}' | sed 's/%//')
used_width=$((($usage*$bar_width)/100))
# color is green if usage < max_usage, else red
if [ "${usage}" -ge "${alert_usage}" ]; then
color=$yellow
elif [ "${usage}" -ge "${max_usage}" ]; then
color=$red
else
color=$green
fi
# print green/red bar until used_width
bar="${color}\uee03"
for ((i=0; i<$used_width; i++)); do
bar+="\uee04"
done
# print dimmmed bar until end
bar+="${color}"
for ((i=$used_width; i<$bar_width; i++)); do
bar+="\uee01"
done
# print empty end if usage < max_usage, else filled
if [ "${usage}" -ge "${max_usage}" ]; then
bar+="${color}\uee05"
else
bar+="${color}\uee02"
fi
# escape color
bar+="${NC}"
# print usage line & bar
echo "${line}" | awk '{ printf("%-31s%+3s used out of %+4s\n", $6, $3, $2); }' | sed -e 's/^/ /'
echo -e "${bar}" | sed -e 's/^/ /'
done