-
Notifications
You must be signed in to change notification settings - Fork 0
/
.barinfo2
158 lines (139 loc) · 3.15 KB
/
.barinfo2
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# -*- mode: Ruby; coding: utf-8 -*-
def active_window_name
`xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) _NET_WM_NAME`.split('"')[1]
end
def cpu_ghz
cpu_mhz / 1024.0
end
def cpu_mhz
a = `cat /proc/cpuinfo | grep MHz`.split("\n").map {|x| (x.split ": ")[1].to_f }
(a.inject(:+)/a.size).to_i
end
def cpu_temperature
temp = `sensors`
sensor_lines = temp.lines.select { |x| /^Core/ =~ x }
sensor_temps = sensor_lines.map { |x| x.gsub( /^Core \d: +\+([0-9.]+).+\n/, '\1').to_f }
("%.01f" % (sensor_temps.inject { |sum,el| sum + el }.to_f / sensor_temps.size)).to_f
end
def ram_usage
ramstat = `cat /proc/meminfo | head -3`.lines.map{|l| l.split[1].to_f/1024/1024 }
ramstat[0]-ramstat[2]
end
def cpu_color
x = cpu_temperature
case x
when 0..30
return "#60f040"
when 30..60
return "#d0f040"
else
return "#f00000"
end
end
# def governor
# `cpupower frequency-info | grep "The governor"`.split('"')[1].capitalize
# end
def ping_speed
begin
`ping -c 1 google.com | grep 64`.split("=")[-1].strip.split[0].to_f
rescue
"--"
end
end
def ping_color(ps)
case ps
when "--"
"#555555"
when 0..30
"#60f040"
when 30..50
"#d0f040"
when 50..70
"#f0d040"
else
"#f00000"
end
end
def battery_pcts
`acpi -b`.split("\n")
end
def battery_color(pct)
case pct[1].to_i
when 90..100
"#50f040"
when 80..89
"#70e040"
when 70..79
"#c0e040"
when 60..69
"#e0e040"
when 50..59
"#f0c040"
when 40..49
"#e09040"
when 30..39
"#f05020"
when 20..29
"#f02020"
when 10..19
"#d02040"
when 0..9
"#f00020"
end
end
$white = "#eeeeee"
def locust
if `hostname`.strip == "locust"
bat0 = { full_text: battery_pcts[0],
color: battery_color(battery_pcts[0])}
bat1 = { full_text: battery_pcts[1],
color: battery_color(battery_pcts[1])}
[bat0, bat1]
else
[]
end
end
def mailnum
mn = File.read(File.expand_path("~/.mailnum")).to_i
case mn
when 0
{full_text: "No new email", color: "#eeeeee"}
when 1
{full_text: "1 new email", color: "#60f040"}
else
{full_text: "#{mn} new emails", color: "#60f040"}
end
end
def ncmpcpp
begin
y = `mpc current`.strip
z = [{ full_text: y, color: $white }]
return z
rescue Exception => e
q = "\n" + Time.now.to_s + "\n" + e.backtrace.join("\n")
STDERR.write(q)
File.open(File.expand_path("~/.barinfo-errors"), "a") do |f|
f.write(q)
end
return []
end
end
############
def spcs(s)
" " + s + " "
end
win = { full_text: spcs("#{active_window_name}"),
color: $white }
ram = { full_text: spcs("RAM: #{"%.1f" % ram_usage} GB"),
color: $white }
cputemp = { full_text: spcs("\u2623: #{cpu_temperature} C"),
color: $white }
cpughz = { full_text: spcs("CPU: #{"%.1f" % cpu_ghz} GHz"),
color: $white }
date = { full_text: spcs(Time.now.strftime("%A %B %-d, %Y, %I:%M:%S %p %Z")),
color: $white }
blank = { full_text: spcs(""),
color: $white }
$update_interval = 0.1
$info = [win] + locust + [date]
update