weather - 如何在 NixOS 中将天气添加到 i3status
问题描述
在 i3 中向状态栏添加天气可以通过多种方式完成,包括:
- py3状态
- 管道
i3status
到自定义 bash 脚本
i3status 不允许在配置文件中包含任意 shell 命令。用于 Python 的 NixOS 环境需要进一步配置,当我使用管道时,i3status
我会丢失颜色格式。如何在不添加额外 i3 扩展的情况下保留颜色格式并添加天气?
解决方案
添加一个 shell 脚本/etc/nixos/i3/weather.sh
(从 Reddit 用户@olemartinorg修改):
#!/bin/sh
# weather.sh
# shell script to prepend i3status with weather
i3status -c /etc/nixos/i3/i3status.conf | while :
do
read line
weather=$(cat ~/.weather.cache)
weather_json='"name":"weather","color":"#FFFFFF", "full_text":'
weather_json+=$(echo -n "$weather" | python -c 'import json,sys; print json.dumps(sys.stdin.read())')
weather_json+='},{'
# Inject our JSON into $line after the first [{
line=${line/[{/[{$weather_json}
echo "$line" || exit 1
done
在你的 NixOs 中创建一个 cronjob configuration.nix
:
services.cron = {
enable = true;
systemCronJobs = [
"*/5 * * * * USERNAME . /etc/profile; curl -s wttr.in/Osnabrueck?format=3 > ~/.weather.cache"
];
};
将“Osnabrueck”替换为您的城市名称和USERNAME
您的用户名。这将创建一个文件,该文件.weather.cache
将包含当地天气作为单行。
最后,更新i3.conf
,替换i3status
为脚本的路径:
bar {
status_command /etc/nixos/i3/weather.sh
tray_output primary
}
nixos-rebuild switch
并启动 i3 ( $mod+Shift+R
)。您现在应该在底部(或 i3 状态栏显示的任何位置)看到您的天气。
推荐阅读
- c - 我不明白。为什么输入 5,6$ 时 x=1
- c++ - C++(Windows):将虚拟键代码字符串表示(“VK_F6”)转换为十六进制(0x75)
- c# - C# 将 IHtmlContent 转换为字符串
- python - 在python中以一对一的方式将元素从1个列表附加到另一个列表的嵌套元素
- python - 如何在一行中拆分单词以在 DataFrame 中创建新行?
- django - 表单中的自定义错误
- javascript - 当我单击菜单按钮(onlick)时,它会打开然后立即关闭
- powershell - 如何获取所有报告的数据源用户名?
- python - 如何制作 Discord.py ping cmd
- python - 为什么我的函数不能根据用户输入正确执行?