waybar: publicip module
This commit is contained in:
@@ -119,7 +119,7 @@
|
||||
},
|
||||
// System monitors
|
||||
"group/monitors": {
|
||||
"modules": ["network#speed", "temperature", "memory", "cpu", "battery", "backlight", "wireplumber"],
|
||||
"modules": ["network#speed", "custom/publicip", "temperature", "memory", "cpu", "battery", "backlight", "wireplumber"],
|
||||
"orientation": "inherit"
|
||||
},
|
||||
"network#speed": {
|
||||
@@ -133,9 +133,18 @@
|
||||
"tooltip-format-wifi": "{essid} {signalStrength}%",
|
||||
"tooltip-format-ethernet": "{ifname} ",
|
||||
"tooltip-format-disconnected": " Disconnected",
|
||||
"max-length": 24,
|
||||
"min-length": 20
|
||||
},
|
||||
"custom/publicip": {
|
||||
"interval": 60,
|
||||
"return-type": "json",
|
||||
"format": " {text}",
|
||||
"tooltip-format": "{alt}",
|
||||
"max-length": 6,
|
||||
"min-length": 6,
|
||||
"exec": "$HOME/.config/waybar/modules/publicip.sh",
|
||||
"on-click": "rm -f $HOME/.config/waybar/modules/publicip.cache && sleep 0.1"
|
||||
},
|
||||
"temperature": {
|
||||
"interval": 5,
|
||||
"thermal-zone": 6,
|
||||
@@ -145,23 +154,23 @@
|
||||
"format-critical": " {temperatureC}°C",
|
||||
"format": "{icon} {temperatureC}°C",
|
||||
"format-icons": ["", "", ""],
|
||||
"max-length": 7,
|
||||
"min-length": 7
|
||||
"max-length": 6,
|
||||
"min-length": 6
|
||||
},
|
||||
"memory": {
|
||||
"interval": 11,
|
||||
// "format": " {used:0.2f} / {total:0.0f} GB",
|
||||
"format": " {percentage}%",
|
||||
"on-click": "killall btop || ghostty -e btop",
|
||||
"min-length": 7,
|
||||
"max-length": 7
|
||||
"max-length": 6,
|
||||
"min-length": 6
|
||||
},
|
||||
"cpu": {
|
||||
"interval": 3,
|
||||
//"format": " {}%", // Icon: microchip
|
||||
"format": " {usage}%",
|
||||
"max-length": 7,
|
||||
"min-length": 7,
|
||||
"max-length": 6,
|
||||
"min-length": 6,
|
||||
"on-click": "killall btop || ghostty -e btop"
|
||||
},
|
||||
"battery": {
|
||||
@@ -175,8 +184,8 @@
|
||||
"format-charging": " {capacity}%",
|
||||
"format-plugged": " {capacity}%",
|
||||
"format-icons": ["", "", "", "", ""],
|
||||
"max-length": 7,
|
||||
"min-length": 7
|
||||
"max-length": 6,
|
||||
"min-length": 6
|
||||
},
|
||||
"backlight": {
|
||||
"device": "$DISPLAY_DEVICE",
|
||||
@@ -187,8 +196,8 @@
|
||||
"format-icons": [""],
|
||||
"on-scroll-down": "brightnessctl -d $DISPLAY_DEVICE set 5%-",
|
||||
"on-scroll-up": "brightnessctl -d $DISPLAY_DEVICE set +5%",
|
||||
"max-length": 7,
|
||||
"min-length": 7
|
||||
"max-length": 6,
|
||||
"min-length": 6
|
||||
},
|
||||
"wireplumber": {
|
||||
"on-click": "pavucontrol",
|
||||
@@ -208,8 +217,8 @@
|
||||
"car": "",
|
||||
"default": ["", "", "", "", "", ""]
|
||||
},
|
||||
"max-length": 7,
|
||||
"min-length": 7
|
||||
"max-length": 6,
|
||||
"min-length": 6
|
||||
},
|
||||
// Hyprland
|
||||
"group/workspaceactions": {
|
||||
|
||||
3
waybar/modules/.gitignore
vendored
Normal file
3
waybar/modules/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
publicip.conf
|
||||
publicip.cache
|
||||
publicip.log
|
||||
47
waybar/modules/publicip.sh
Executable file
47
waybar/modules/publicip.sh
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/bin/env bash
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Entries in publicip.conf:
|
||||
# IP_QUERY_URL: URL to query public IP of the system.
|
||||
# param: none
|
||||
# return: JSON object with "ip" field.
|
||||
# note: This URL will be queried with short intervals (60s for example),
|
||||
# therefore it may not be a good idea to use a public API with
|
||||
# a limited number of calls.
|
||||
# IP_INFO_URL: URL to query IP location.
|
||||
# param: <ip>
|
||||
# return: JSON object with "country_code" field.
|
||||
# note: This URL will only be quetried when public IP changes or when "force" is given as parameter.
|
||||
|
||||
path="$(dirname "$(readlink -f "$0")")"
|
||||
cache_file="$path/publicip.cache"
|
||||
config_file="$path/publicip.conf"
|
||||
time_log="$path/publicip.log"
|
||||
|
||||
[ -f "$config_file" ] || exit 1
|
||||
. "$config_file"
|
||||
[ -z "$IP_QUERY_URL" ] && exit 1
|
||||
[ -z "$IP_INFO_URL" ] && exit 1
|
||||
[ "$1" == "force" ] && rm -f "$cache_file"
|
||||
[ -f "$cache_file" ] && . "$cache_file"
|
||||
|
||||
|
||||
ip_current=$(curl -s -L "$IP_QUERY_URL" | jq -r '.ip')
|
||||
[ -z "$ip_current" ] && exit 1
|
||||
|
||||
if [ "$ip_current" != "$CACHED_IP" ]; then
|
||||
echo "$(date +%Y-%m-%dT%H:%M:%S) - IP changed: $CACHED_IP -> $ip_current" >> "$time_log"
|
||||
CACHED_IP="$ip_current"
|
||||
|
||||
ip_info_url=${IP_INFO_URL//<ip>/$ip_current}
|
||||
CACHED_CODE=$(curl -s -L "$ip_info_url" | jq -r '.country_code')
|
||||
[ -z "$CACHED_CODE" ] && CACHED_CODE="N/A"
|
||||
echo "CACHED_IP=$CACHED_IP" > "$cache_file"
|
||||
echo "CACHED_CODE=$CACHED_CODE" >> "$cache_file"
|
||||
notify-send "New Public IP detected" "New IP: $ip_current\nCountry: $CACHED_CODE"
|
||||
fi
|
||||
|
||||
jq -n --unbuffered --compact-output \
|
||||
--arg ip "$CACHED_IP" \
|
||||
--arg country "$CACHED_CODE" \
|
||||
'{alt: $ip, text: $country}'
|
||||
@@ -116,6 +116,7 @@ tooltip {
|
||||
#custom-hyprPicker,
|
||||
#custom-power-menu,
|
||||
#custom-spotify,
|
||||
#custom-publicip,
|
||||
#custom-weather,
|
||||
#custom-weather.severe,
|
||||
#custom-weather.sunnyDay,
|
||||
@@ -144,27 +145,33 @@ tooltip {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#custom-publicip {
|
||||
background: transparent;
|
||||
color: @peach;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#temperature {
|
||||
background: transparent;
|
||||
color: @maroon;
|
||||
color: @yellow;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#memory {
|
||||
color: @peach;
|
||||
color: @green;
|
||||
background: transparent;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#cpu {
|
||||
color: @yellow;
|
||||
color: @teal;
|
||||
background: transparent;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#battery {
|
||||
background: transparent;
|
||||
color: #c0caf5;
|
||||
color: @sapphire;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@@ -176,13 +183,13 @@ tooltip {
|
||||
|
||||
#backlight {
|
||||
background: transparent;
|
||||
color: @teal;
|
||||
color: @blue;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#wireplumber {
|
||||
background: transparent;
|
||||
color: @sapphire;
|
||||
color: @lavender;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,7 @@ tooltip {
|
||||
#custom-hyprPicker,
|
||||
#custom-power-menu,
|
||||
#custom-spotify,
|
||||
#custom-publicip,
|
||||
#custom-weather,
|
||||
#custom-weather.severe,
|
||||
#custom-weather.sunnyDay,
|
||||
@@ -144,27 +145,33 @@ tooltip {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#custom-publicip {
|
||||
background: transparent;
|
||||
color: @peach;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#temperature {
|
||||
background: transparent;
|
||||
color: @maroon;
|
||||
color: @yellow;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#memory {
|
||||
color: @peach;
|
||||
color: @green;
|
||||
background: transparent;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#cpu {
|
||||
color: @yellow;
|
||||
color: @teal;
|
||||
background: transparent;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
#battery {
|
||||
background: transparent;
|
||||
color: #c0caf5;
|
||||
color: @sapphire;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@@ -176,13 +183,13 @@ tooltip {
|
||||
|
||||
#backlight {
|
||||
background: transparent;
|
||||
color: @teal;
|
||||
color: @blue;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#wireplumber {
|
||||
background: transparent;
|
||||
color: @sapphire;
|
||||
color: @lavender;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user