Commit 5be6ce886a8b
Changed files (3)
home
common
services
pkgs
my
scripts
home/common/services/redhat-vpn-disconnect.desktop
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Name=Red Hat VPN Disconnect
+Comment=Disconnect from Red Hat VPN
+Exec=redhat-vpn-disconnect
+Type=Application
+Terminal=false
+Categories=Network;
+Icon=network-vpn-disconnected;
home/common/services/redhat.nix
@@ -1,5 +1,7 @@
{ ... }:
{
- # Red Hat VPN desktop launcher
+ # Red Hat VPN desktop launchers
home.file.".local/share/applications/redhat-vpn.desktop".source = ./redhat-vpn.desktop;
+ home.file.".local/share/applications/redhat-vpn-disconnect.desktop".source =
+ ./redhat-vpn-disconnect.desktop;
}
pkgs/my/scripts/bin/redhat-vpn-disconnect
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+# Disconnect from RedHat VPN
+# This will list active VPN connections and allow you to disconnect from them
+set -e
+
+# Detect desktop environment and available tools
+DESKTOP="${XDG_CURRENT_DESKTOP:-}"
+GRAPHICS=1
+
+# Check if running in a graphical environment
+if [[ "$DESKTOP" != "sway" && "$DESKTOP" != "niri" ]]; then
+ if ! command -v xset &>/dev/null; then
+ GRAPHICS=0
+ elif ! timeout 1s xset q &>/dev/null; then
+ GRAPHICS=0
+ fi
+fi
+
+# Get active VPN connections
+active_vpns=$(nmcli connection show --active | grep vpn)
+
+if [[ -z "$active_vpns" ]]; then
+ NOTIFY_CMD="notify-send"
+ if [[ GRAPHICS -eq 0 ]]; then
+ NOTIFY_CMD="echo"
+ fi
+ $NOTIFY_CMD "No active VPN" "No VPN connection is currently active."
+ exit 0
+fi
+
+# Select VPN connection to disconnect based on environment
+if [[ GRAPHICS -eq 0 ]]; then
+ # Terminal: use fzf
+ connection="$(echo "$active_vpns" | fzf)"
+elif [[ "$DESKTOP" == "sway" || "$DESKTOP" == "niri" ]]; then
+ # Wayland compositors (Sway/Niri): use fuzzel
+ connection="$(echo "$active_vpns" | awk '{print $1, $2, $3, $4}' | fuzzel --dmenu --prompt "Disconnect VPN: ")"
+else
+ # X11: use zenity
+ connection="$(echo "$active_vpns" | zenity --list --title "Active Red Hat VPNs" --text "Choose VPN to disconnect.." --column "Name" --width=600 --height=450)"
+fi
+
+NOTIFY_CMD="notify-send"
+if [[ GRAPHICS -eq 0 ]]; then
+ NOTIFY_CMD="echo"
+fi
+
+uuid=$(echo "${connection}" | awk '{print $4}')
+name=$(echo "${connection}" | awk '{print $1 $2 $3}')
+
+nmcli connection down "${uuid}"
+$NOTIFY_CMD "VPN ${name} disconnected." "You have been disconnected from the Red Hat VPN."