-
Notifications
You must be signed in to change notification settings - Fork 0
/
status-bar.lua
132 lines (116 loc) · 4.47 KB
/
status-bar.lua
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
local wezterm = require "wezterm"
local battery_status = require "battery-status"
local config_parser = require "parse-config"
local stock_quotes = require "stock-quotes"
local system_status = require "system-status.system-status"
local util = require "util.util"
local weather = require "weather"
local wifi_status = require "wifi-status"
local config = config_parser.get_config()
local stock_quotes_config = config["status_bar"]["stock_quotes"]
local system_status_config = config["status_bar"]["system_status"]
local weather_config = config["status_bar"]["weather"]
local wifi_status_config = config["status_bar"]["wifi_status"]
status_bar = {}
function status_bar.update_status_bar(cwd)
-- update the data files as needed
stock_quotes.update_json(stock_quotes_config)
weather.update_json(weather_config)
wifi_status.update_json(config)
local cells = {}
-- clock
if config["status_bar"]["toggles"]["show_clock"] then
local date = wezterm.strftime "%a %b %-d %H:%M"
table.insert(cells, util.pad_string(2, 2, date))
end
-- battery
if config["status_bar"]["toggles"]["show_battery"] then
if #wezterm.battery_info() > 0 then
for _, b in ipairs(wezterm.battery_info()) do
icon, battery_percent = battery_status.get_battery_status(b)
bat = icon .. " " .. battery_percent
table.insert(cells, util.pad_string(1, 1, bat))
end
end
end
-- weather
if weather_config["enabled"] then
if weather_config["api_key"] == nil then
table.insert(cells, util.pad_string(2, 2, "Weather: Missing API key"))
else
weather_data = weather.get_weather(weather_config)
if weather_data ~= nil then
for _, location_data in ipairs(weather_data) do
table.insert(cells, location_data)
end
end
end
end
-- stock quotes
if stock_quotes_config["enabled"] then
stock_quote_data = stock_quotes.get_stock_quotes(stock_quotes_config)
if stock_quote_data ~= nil then
for _, stock_quote in ipairs(stock_quote_data) do
table.insert(cells, stock_quote)
end
end
stock_index_data = stock_quotes.get_stock_indexes(stock_quotes_config)
if stock_index_data ~= nil then
for _, stock_index in ipairs(stock_index_data) do
table.insert(cells, stock_index)
end
end
end
-- wifi status
if wifi_status_config["enabled"] then
wifi_data = wifi_status.get_wifi_status(config)
if wifi_data ~= nil then
for _, interface_data in ipairs(wifi_data) do
table.insert(cells, interface_data)
end
end
end
-- system status
if system_status_config["enabled"] then
if system_status_config["toggles"]["show_load_averages"] then
load_averages = system_status.get_load_averages(config)
if load_averages ~= nil then
table.insert(cells, load_averages)
end
end
if system_status_config["toggles"]["show_uptime"] then
system_uptime = system_status.get_system_uptime(config)
if system_uptime ~= nil then
table.insert(cells, system_uptime)
end
end
if system_status_config["toggles"]["show_cpu_usage"] then
cpu_usage = system_status.get_cpu_usage(config)
if cpu_usage ~= nil then
table.insert(cells, cpu_usage)
end
end
if system_status_config["toggles"]["show_memory_usage"] then
memory_usage = system_status.get_memory_usage(config)
if memory_usage ~= nil then
table.insert(cells, memory_usage)
end
end
if system_status_config["toggles"]["show_disk_usage"] then
disk_usage = system_status.get_disk_usage(config)
if disk_usage ~= nil then
for _, disk_usage_data in ipairs(disk_usage) do
table.insert(cells, disk_usage_data)
end
end
end
if system_status_config["toggles"]["show_network_throughput"] then
network_throughput = system_status.get_network_throughput(config)
if network_throughput ~= nil then
table.insert(cells, network_throughput)
end
end
end
return cells
end
return status_bar