forked from wymiller/nix-config-v2
mod: show public ip in waybar
on click to show
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"layer": "top",
|
"layer": "top",
|
||||||
"modules-left": ["sway/workspaces"],
|
"modules-left": ["sway/workspaces"],
|
||||||
"modules-center": ["clock"],
|
"modules-center": ["clock"],
|
||||||
"modules-right": ["custom/playerctl", "custom/weather", "pulseaudio", "network", "tray"],
|
"modules-right": ["custom/playerctl", "custom/weather", "pulseaudio", "custom/network", "tray"],
|
||||||
"sway/workspaces": {
|
"sway/workspaces": {
|
||||||
"disable-scroll": true,
|
"disable-scroll": true,
|
||||||
"all-outputs": true,
|
"all-outputs": true,
|
||||||
@@ -34,11 +34,11 @@
|
|||||||
"exec": "wttrbar --fahrenheit --main-indicator 'temp_F' --location 'Grand Rapids'",
|
"exec": "wttrbar --fahrenheit --main-indicator 'temp_F' --location 'Grand Rapids'",
|
||||||
"return-type": "json"
|
"return-type": "json"
|
||||||
},
|
},
|
||||||
"network": {
|
"custom/network": {
|
||||||
"format-wifi": " {essid} ({signalStrength}%)",
|
"format": "{text}",
|
||||||
"format-ethernet": " {ipaddr}",
|
"return-type": "json",
|
||||||
"format-disconnected": "⚠ Disconnected",
|
"exec": "bash $HOME/.config/waybar/network.sh",
|
||||||
"family": "ipv4",
|
"on-click": "bash $HOME/.config/waybar/network.sh toggle",
|
||||||
"interval": 5,
|
"interval": 5,
|
||||||
"tooltip": false
|
"tooltip": false
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -u
|
||||||
|
|
||||||
|
state_dir="${XDG_RUNTIME_DIR:-/tmp}/waybar-${UID}"
|
||||||
|
state_file="$state_dir/public-ip"
|
||||||
|
|
||||||
|
if [[ ${1:-} == toggle ]]; then
|
||||||
|
mkdir -p -m 700 "$state_dir"
|
||||||
|
if [[ -s $state_file ]]; then
|
||||||
|
: > "$state_file"
|
||||||
|
else
|
||||||
|
public_ip=$(curl -4fsS --max-time 5 https://wtfismyip.com/json 2>/dev/null |
|
||||||
|
jq -er '.YourFuckingIPAddress | select(type == "string") | split(".") |
|
||||||
|
select(length == 4 and all(.[]; test("^[0-9]{1,3}$") and (tonumber <= 255))) |
|
||||||
|
join(".")' 2>/dev/null) || exit 0
|
||||||
|
printf '%s\n' "$public_ip" > "$state_file"
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
route=$(ip -4 route get 1.1.1.1 2>/dev/null) || route=
|
||||||
|
if [[ ! $route =~ [[:space:]]dev[[:space:]]([^[:space:]]+) ]]; then
|
||||||
|
jq -cn '{text: "⚠ Disconnected", class: "disconnected"}'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
interface=${BASH_REMATCH[1]}
|
||||||
|
if [[ ! $route =~ [[:space:]]src[[:space:]]([0-9.]+) ]]; then
|
||||||
|
jq -cn '{text: "⚠ Disconnected", class: "disconnected"}'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
local_ip=${BASH_REMATCH[1]}
|
||||||
|
|
||||||
|
if [[ -s $state_file ]]; then
|
||||||
|
jq -cn --rawfile ip "$state_file" '{text: (" " + ($ip | rtrimstr("\n"))), class: "public"}'
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $(nmcli -g GENERAL.TYPE device show "$interface" 2>/dev/null) == wifi ]]; then
|
||||||
|
essid=$(nmcli -g GENERAL.CONNECTION device show "$interface" 2>/dev/null | head -n 1)
|
||||||
|
signal=$(nmcli -t -f IN-USE,SIGNAL device wifi list ifname "$interface" --rescan no 2>/dev/null |
|
||||||
|
awk -F: '$1 == "*" { print $2; exit }')
|
||||||
|
if [[ -n $essid && $essid != -- ]]; then
|
||||||
|
text=" $essid"
|
||||||
|
[[ -n $signal ]] && text="${text} (${signal}%)"
|
||||||
|
else
|
||||||
|
text=" $local_ip"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
text=" $local_ip"
|
||||||
|
fi
|
||||||
|
jq -cn --arg text "$text" '{text: $text, class: "connected"}'
|
||||||
@@ -31,7 +31,7 @@ window#waybar {
|
|||||||
#cpu,
|
#cpu,
|
||||||
#memory,
|
#memory,
|
||||||
#pulseaudio,
|
#pulseaudio,
|
||||||
#network,
|
#custom-network,
|
||||||
#battery,
|
#battery,
|
||||||
#clock,
|
#clock,
|
||||||
#custom-playerctl {
|
#custom-playerctl {
|
||||||
@@ -65,7 +65,7 @@ window#waybar {
|
|||||||
animation-direction: alternate;
|
animation-direction: alternate;
|
||||||
}
|
}
|
||||||
|
|
||||||
#network.disconnected {
|
#custom-network.disconnected {
|
||||||
color: #cc241d;
|
color: #cc241d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ in {
|
|||||||
xdg.configFile."sway/config".source = lib.mkForce (dirs.defaults + /sway/config);
|
xdg.configFile."sway/config".source = lib.mkForce (dirs.defaults + /sway/config);
|
||||||
xdg.configFile."waybar/config".source = lib.mkForce (dirs.defaults + /waybar/config);
|
xdg.configFile."waybar/config".source = lib.mkForce (dirs.defaults + /waybar/config);
|
||||||
xdg.configFile."waybar/style.css".source = lib.mkForce (dirs.defaults + /waybar/style.css);
|
xdg.configFile."waybar/style.css".source = lib.mkForce (dirs.defaults + /waybar/style.css);
|
||||||
|
xdg.configFile."waybar/network.sh".source = dirs.defaults + /waybar/network.sh;
|
||||||
|
|
||||||
|
home.packages = with pkgs; [ curl iproute2 networkmanager ];
|
||||||
|
|
||||||
programs.wofi = {
|
programs.wofi = {
|
||||||
enable = pkgs.stdenv.isLinux;
|
enable = pkgs.stdenv.isLinux;
|
||||||
|
|||||||
Reference in New Issue
Block a user