- Go 99.6%
- Dockerfile 0.4%
|
Some checks failed
Test Build / test-build (cmw-linux-amd64, amd64, linux) (push) Successful in 2m21s
Test Build / test-build (cmw-darwin-amd64, amd64, darwin) (push) Successful in 2m23s
Test Build / test-build (cmw-darwin-arm64, arm64, darwin) (push) Successful in 2m23s
Test / skip-on-master (push) Has been skipped
Test Build / test-build (cmw-windows-amd64, amd64, windows) (push) Successful in 2m10s
Test Build / test-build (cmw-linux-arm64, arm64, linux) (push) Successful in 2m12s
Test / test (push) Failing after 3m0s
|
||
|---|---|---|
| .forgejo/workflows | ||
| .drone.yml | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| main.go | ||
| main_test.go | ||
| README.md | ||
| renovate.json | ||
Go CMW
go-cmw is a cmw rewrite in Go.
Usage
go-cmw features a good command-line interface thanks to kingpin.v2.
$ go-cmw --help
usage: go-cmw [<flags>]
A small terminal wrapper around the wttr.in weather endpoint.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-L, --location=LOCATION Specify explicite location (--expert-mode)
-l, --language=LANGUAGE Specify explicite language (--expert-mode)
--v2 Display Data-Rich output
-m, --metric Display weather in metric
-u, --uscs Display weather in imperial
-M, --meter-second Display wind in m/s
-z, --zero Display current weather
-o, --one Display current weather + 1 day
-w, --two Display current weather + 2 days
-A, --ignore-user-agent Ignore User-Agent and force ANSI output
-F, --follow-link Do not display the 'Follow' line
-n, --narrow Display narrow view (only day/night)
-q, --quiet Display quiet version (no weather report)
-Q, --super-quiet Display super quiet version (no weather report and no city)
-N, --no-colors Display no colors (always enabled on windows
-P, --png Download a weather PNG image
-p, --add-frame Add a frame to the output (PNG only)
-t, --transparency=255 Set transparency level (0-255) (PNG only) (--expert-mode)
-d, --download Enables download mode (--expert-mode)
--file-name="" Name download file (--expert-mode)
-O, --one-liner One liner outpet (for the terminal multiplexer lovers out there)
--format=FORMAT Specify a format query (e.g. "%l:+%c+%t") (--expert-mode)
--free-style=FREE-STYLE Specify a free-style API call (--expert-mode)
--expert-mode Print expert mode information
--version Show application version.
On top of the following command-line flags, go-cmw can also take advantage of environment variables --expert-mode.
$ go-cmw --zero
Weather report: Paris
\ / Clear
.-. 1..4 °C
― ( ) ― ↗ 11 km/h
`-’ 10 km
/ \ 0.3 mm
go-cmw makes it easier to integrate the weather with your favorite terminal multiplexer.
$ go-cmw --one-liner
Paris: ☀️ +4°C
Terminal Multiplexer Integration
tmux
Add to your ~/.tmux.conf:
# Let us update sensibly every 30 minutes
set -g status-interval 1800
WEATHER='#(go-cmw --one-liner)'
set -g status-right "$WEATHER"
Or with a more detailed format:
set -g status-interval 1800
WEATHER='#(go-cmw --metric --one-liner)'
set -g status-right "$WEATHER | %H:%M"
screen
Add to your ~/.screenrc:
# Weather in the hardstatus line (update every 30 minutes)
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%{g}][%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c%{g}]%{= kG}[Weather: $(go-cmw --one-liner)]'
zellij
Add to your ~/.config/zellij/config.kdl:
// In the layout or plugins section
plugins {
weather {
path "command:go-cmw"
args "--one-liner"
}
}
Or use the status bar:
// ~/.config/zellij/config.kdl
keybinds {
shared_except "locked" {
Ctrl+Shift+W {
RunCommand "go-cmw" "--one-liner"
Floating true
}
}
}
fish shell
Add to your ~/.config/fish/functions/fish_prompt.fish:
function fish_prompt
set_color cyan
echo -n (go-cmw --one-liner)
set_color normal
echo -n " | "
set_color green
echo -n (whoami)@(hostname)
set_color normal
echo -n " "
set_color yellow
echo -n (prompt_pwd)
set_color normal
echo -n " $ "
end
bash
Add to your ~/.bashrc:
# Weather in prompt (update every 30 minutes via PROMPT_COMMAND)
WEATHER_CACHE=""
WEATHER_CACHE_TIME=0
get_weather() {
local now=$(date +%s)
if (( now - WEATHER_CACHE_TIME > 1800 )); then
WEATHER_CACHE=$(go-cmw --one-liner)
WEATHER_CACHE_TIME=$now
fi
echo "$WEATHER_CACHE"
}
PROMPT_COMMAND='PS1="$(get_weather) | \u@\h:\w$ "'
zsh
Add to your ~/.zshrc:
# Weather in prompt (update every 30 minutes)
autoload -Uz add-zsh-hook
weather_prompt() {
local now=$(date +%s)
if (( ${WEATHER_CACHE_TIME:-0} < now - 1800 )); then
WEATHER_CACHE=$(go-cmw --one-liner)
WEATHER_CACHE_TIME=$now
fi
echo "$WEATHER_CACHE"
}
add-zsh-hook precmd weather_prompt
PROMPT='$(weather_prompt) | %n@%m:%~$ '
kitty terminal
Add to your ~/.config/kitty/kitty.conf:
# Custom tab title with weather
tab_title_template "Weather: {go-cmw --one-liner} | {activity}"
Or use the remote control:
# Update tab title with weather
kitty @ set-tab-title "$(go-cmw --one-liner)"
alacritty
Alacritty doesn't have built-in status bar support, but you can use it with tmux or screen as shown above.
wezterm
Add to your ~/.wezterm.lua:
wezterm.on("update-right-status", function(window, pane)
local weather = io.popen("go-cmw --one-liner"):read("*a")
window:set_right_status(wezterm.format({
{ Text = weather .. " " },
}))
end)
Powerline / Oh My Posh
Create a custom segment for Oh My Posh:
{
"type": "text",
"style": "plain",
"foreground": "#ffffff",
"template": "{{ if .Env.GO_CMW_ONE_LINER }}{{ .Env.GO_CMW_ONE_LINER }}{{ end }}",
"properties": {
"command": "go-cmw --one-liner"
}
}
Custom Scripts
You can also create a simple script for use anywhere:
#!/bin/bash
# ~/.local/bin/weather-status
go-cmw --one-liner
Then use it in any configuration:
# In tmux
WEATHER='#(~/.local/bin/weather-status)'
# In bash prompt
PROMPT_COMMAND='PS1="$(~/.local/bin/weather-status) | \u@\h:\w$ "'
Expert Mode
The commands labeled --expert-mode have special functionality attached to them.
Some of them can be used as environment variables while others override go-cmw
default functionality to provide the user with more flexible interface.
For more information about commands labeled --expert-mode
$ go-cmw --expert-mode
Reason
This project is a journey of learning Golang. If you would like to make an MR, please go right ahead, it would be a good learning process for me.