WezTermのright-statusを使っていますか?
Photo by Wolfgang Hasselmann on Unsplash
2025年6月16日の月曜
なんだか週末からめちゃくちゃ暑くなってきました。
昨日29℃、今日は31℃、明日は34℃(え?w)
WezTermのright-statusで天気を表示できたら良いなと・・・
right-status
実はいろいろやってて、やっとできました・・・😅
5分間隔でがなかなかうまくいかなかった😂
local wezterm = require 'wezterm'
-- 省略
-------------------------------------------------------------------------------
-- right-status
local colors = {
"#3c1361",
"#52307c",
"#663a82",
"#7c5295",
"#b491c8",
"#d3a0f5",
}
local text_fg = "#c0c0c0"
local SOLID_LEFT_ARROW = utf8.char(0xe0b2)
local weather_cache = "🌦 Loading..."
local last_weather_update = 0
local weather_update_interval = 300
local function fetch_weather()
wezterm.log_info("Fetching weather data...")
local handle = io.popen("curl -s 'wttr.in/Tokyo?format=4'")
if handle then
local result = handle:read("*a")
handle:close()
if result and result ~= "" then
weather_cache = result:gsub("\n", "")
else
weather_cache = "🌧 Weather: N/A"
end
else
weather_cache = "🌧 Weather Error"
end
end
wezterm.on("gui-startup", function()
last_weather_update = os.time()
fetch_weather()
end)
wezterm.on("update-right-status", function(window, pane)
local cells = {}
local now = os.time()
if now - last_weather_update > weather_update_interval then
last_weather_update = now
fetch_weather()
end
table.insert(cells, " " .. weather_cache .. " ")
table.insert(cells, " " .. wezterm.strftime("⏱️ %F %T") .. " ")
for _, b in ipairs(wezterm.battery_info()) do
table.insert(cells, " 🔋 " .. string.format("%.0f%%", b.state_of_charge * 100) .. " ")
end
local elements = {}
local num_cells = 0
local function push(text, is_last)
local cell_no = num_cells + 1
table.insert(elements, { Foreground = { Color = text_fg } })
table.insert(elements, { Background = { Color = colors[cell_no] or "#000000" } })
table.insert(elements, { Text = text })
if not is_last then
table.insert(elements, { Foreground = { Color = colors[cell_no + 1] or "#000000" } })
table.insert(elements, { Text = SOLID_LEFT_ARROW })
end
num_cells = num_cells + 1
end
while #cells > 0 do
local cell = table.remove(cells, 1)
push(cell, #cells == 0)
end
window:set_right_status(wezterm.format(elements))
end)
-------------------------------------------------------------------------------
-- and finally, return the configuration to wezterm
return config
試行錯誤して、やっとできた!
動作もだいたい5分おき👍
どうでもいいけど、まだ6月中旬なのに暑すぎません?
と毎年言ってる気がする・・・🤔