-
Notifications
You must be signed in to change notification settings - Fork 7
/
disk.coffee
87 lines (64 loc) · 2.06 KB
/
disk.coffee
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
require('./assets/lib/piety')($, document)
## Colors Used by the chart
colors =
low: 'rgb(133, 188, 86)'
med: 'orange'
high: 'rgb(255,44,37)'
back: 'rgba(0,0,0,0.3)'
# Try 'donut'
chartType = 'pie'
## Width of the chart
chartWidth = 15
# Which disk to show a chart for
diskIndex = 0
# Use base 10 numbers, i.e. 1GB = 1000MB. Leave this true to show disk sizes as
# OS X would (since Snow Leopard)
base10 = true
# Max size in (GB) you want to compare your free space to be
# if set to null, compares to your total disk size
# (I found I never have more than 50GB, so I set it to that)
maxFreeSpace = null
command: "df -#{if base10 then 'H' else 'h'} | grep '/dev/' | while read -r line; do fs=$(echo $line | awk '{print $1}'); name=$(diskutil info $fs | grep 'Volume Name' | awk '{print substr($0, index($0,$3))}'); echo $(echo $line | awk '{print $2, $3, $4, $5}') $(echo $name | awk '{print substr($0, index($0,$1))}'); done"
refreshFrequency: 20000
render: ()-> """
<div class="disk-info">
<span class='chart'></span>
<span class='number'></span>
</div>
"""
update: (output, el) ->
disks = output.split('\n')
# ## Get one disk to show stats for
disk = disks[diskIndex]
## ex. disk = "379G 346G 33G 92% Macintosh HD"
args = disk.split(' ')
## Get variables from args
[total, used, free, pctg] = args;
## Take out Units
freeNum = free.replace(/G|Gi/, '');
totalNum = total.replace(/G|Gi/, '');
fill = colors.low
## Medium Threshold
if freeNum < 25
fill = colors.med
## High Threshold
if freeNum < 10
fill = colors.high
maxFreeSpace = totalNum if not maxFreeSpace?
## Set text to free + inactive
$(".number", el).text(free)
## Set chart up
$('.chart', el).html("#{maxFreeSpace - freeNum}/#{maxFreeSpace}").peity chartType,
fill: [fill, colors.background]
width: chartWidth
style: """
left: 150px
top: 7px
color: white
font: 12px Inconsolata, monospace, Helvetica Neue, sans-serif
-webkit-font-smoothing: antialiased
.number
vertical-align top
.chart
vertical-align top
"""