waybar: publicip module
This commit is contained in:
@@ -119,7 +119,7 @@
|
|||||||
},
|
},
|
||||||
// System monitors
|
// System monitors
|
||||||
"group/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"
|
"orientation": "inherit"
|
||||||
},
|
},
|
||||||
"network#speed": {
|
"network#speed": {
|
||||||
@@ -133,9 +133,18 @@
|
|||||||
"tooltip-format-wifi": "{essid} {signalStrength}%",
|
"tooltip-format-wifi": "{essid} {signalStrength}%",
|
||||||
"tooltip-format-ethernet": "{ifname} ",
|
"tooltip-format-ethernet": "{ifname} ",
|
||||||
"tooltip-format-disconnected": " Disconnected",
|
"tooltip-format-disconnected": " Disconnected",
|
||||||
"max-length": 24,
|
|
||||||
"min-length": 20
|
"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": {
|
"temperature": {
|
||||||
"interval": 5,
|
"interval": 5,
|
||||||
"thermal-zone": 6,
|
"thermal-zone": 6,
|
||||||
@@ -145,23 +154,23 @@
|
|||||||
"format-critical": " {temperatureC}°C",
|
"format-critical": " {temperatureC}°C",
|
||||||
"format": "{icon} {temperatureC}°C",
|
"format": "{icon} {temperatureC}°C",
|
||||||
"format-icons": ["", "", ""],
|
"format-icons": ["", "", ""],
|
||||||
"max-length": 7,
|
"max-length": 6,
|
||||||
"min-length": 7
|
"min-length": 6
|
||||||
},
|
},
|
||||||
"memory": {
|
"memory": {
|
||||||
"interval": 11,
|
"interval": 11,
|
||||||
// "format": " {used:0.2f} / {total:0.0f} GB",
|
// "format": " {used:0.2f} / {total:0.0f} GB",
|
||||||
"format": " {percentage}%",
|
"format": " {percentage}%",
|
||||||
"on-click": "killall btop || ghostty -e btop",
|
"on-click": "killall btop || ghostty -e btop",
|
||||||
"min-length": 7,
|
"max-length": 6,
|
||||||
"max-length": 7
|
"min-length": 6
|
||||||
},
|
},
|
||||||
"cpu": {
|
"cpu": {
|
||||||
"interval": 3,
|
"interval": 3,
|
||||||
//"format": " {}%", // Icon: microchip
|
//"format": " {}%", // Icon: microchip
|
||||||
"format": " {usage}%",
|
"format": " {usage}%",
|
||||||
"max-length": 7,
|
"max-length": 6,
|
||||||
"min-length": 7,
|
"min-length": 6,
|
||||||
"on-click": "killall btop || ghostty -e btop"
|
"on-click": "killall btop || ghostty -e btop"
|
||||||
},
|
},
|
||||||
"battery": {
|
"battery": {
|
||||||
@@ -175,8 +184,8 @@
|
|||||||
"format-charging": " {capacity}%",
|
"format-charging": " {capacity}%",
|
||||||
"format-plugged": " {capacity}%",
|
"format-plugged": " {capacity}%",
|
||||||
"format-icons": ["", "", "", "", ""],
|
"format-icons": ["", "", "", "", ""],
|
||||||
"max-length": 7,
|
"max-length": 6,
|
||||||
"min-length": 7
|
"min-length": 6
|
||||||
},
|
},
|
||||||
"backlight": {
|
"backlight": {
|
||||||
"device": "$DISPLAY_DEVICE",
|
"device": "$DISPLAY_DEVICE",
|
||||||
@@ -187,8 +196,8 @@
|
|||||||
"format-icons": [""],
|
"format-icons": [""],
|
||||||
"on-scroll-down": "brightnessctl -d $DISPLAY_DEVICE set 5%-",
|
"on-scroll-down": "brightnessctl -d $DISPLAY_DEVICE set 5%-",
|
||||||
"on-scroll-up": "brightnessctl -d $DISPLAY_DEVICE set +5%",
|
"on-scroll-up": "brightnessctl -d $DISPLAY_DEVICE set +5%",
|
||||||
"max-length": 7,
|
"max-length": 6,
|
||||||
"min-length": 7
|
"min-length": 6
|
||||||
},
|
},
|
||||||
"wireplumber": {
|
"wireplumber": {
|
||||||
"on-click": "pavucontrol",
|
"on-click": "pavucontrol",
|
||||||
@@ -208,8 +217,8 @@
|
|||||||
"car": "",
|
"car": "",
|
||||||
"default": ["", "", "", "", "", ""]
|
"default": ["", "", "", "", "", ""]
|
||||||
},
|
},
|
||||||
"max-length": 7,
|
"max-length": 6,
|
||||||
"min-length": 7
|
"min-length": 6
|
||||||
},
|
},
|
||||||
// Hyprland
|
// Hyprland
|
||||||
"group/workspaceactions": {
|
"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-hyprPicker,
|
||||||
#custom-power-menu,
|
#custom-power-menu,
|
||||||
#custom-spotify,
|
#custom-spotify,
|
||||||
|
#custom-publicip,
|
||||||
#custom-weather,
|
#custom-weather,
|
||||||
#custom-weather.severe,
|
#custom-weather.severe,
|
||||||
#custom-weather.sunnyDay,
|
#custom-weather.sunnyDay,
|
||||||
@@ -144,27 +145,33 @@ tooltip {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#custom-publicip {
|
||||||
|
background: transparent;
|
||||||
|
color: @peach;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
#temperature {
|
#temperature {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: @maroon;
|
color: @yellow;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#memory {
|
#memory {
|
||||||
color: @peach;
|
color: @green;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#cpu {
|
#cpu {
|
||||||
color: @yellow;
|
color: @teal;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#battery {
|
#battery {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: #c0caf5;
|
color: @sapphire;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,13 +183,13 @@ tooltip {
|
|||||||
|
|
||||||
#backlight {
|
#backlight {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: @teal;
|
color: @blue;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#wireplumber {
|
#wireplumber {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: @sapphire;
|
color: @lavender;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ tooltip {
|
|||||||
#custom-hyprPicker,
|
#custom-hyprPicker,
|
||||||
#custom-power-menu,
|
#custom-power-menu,
|
||||||
#custom-spotify,
|
#custom-spotify,
|
||||||
|
#custom-publicip,
|
||||||
#custom-weather,
|
#custom-weather,
|
||||||
#custom-weather.severe,
|
#custom-weather.severe,
|
||||||
#custom-weather.sunnyDay,
|
#custom-weather.sunnyDay,
|
||||||
@@ -144,27 +145,33 @@ tooltip {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#custom-publicip {
|
||||||
|
background: transparent;
|
||||||
|
color: @peach;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
#temperature {
|
#temperature {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: @maroon;
|
color: @yellow;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#memory {
|
#memory {
|
||||||
color: @peach;
|
color: @green;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#cpu {
|
#cpu {
|
||||||
color: @yellow;
|
color: @teal;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#battery {
|
#battery {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: #c0caf5;
|
color: @sapphire;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,13 +183,13 @@ tooltip {
|
|||||||
|
|
||||||
#backlight {
|
#backlight {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: @teal;
|
color: @blue;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#wireplumber {
|
#wireplumber {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: @sapphire;
|
color: @lavender;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user