diff options
-rw-r--r-- | .config/waybar/config | 4 | ||||
-rwxr-xr-x | .local/bin/iwctl-re | 43 |
2 files changed, 39 insertions, 8 deletions
diff --git a/.config/waybar/config b/.config/waybar/config index d5750b2..7fb3289 100644 --- a/.config/waybar/config +++ b/.config/waybar/config @@ -38,8 +38,8 @@ "format": "{ipaddr}", "format-disconnected": "Offline", "interval": 1, - "on-click-right": "~/.local/bin/iwctl-re", - "on-click-middle": "notify-send 'WLAN Reload' 'Restart iwd.service'; sudo systemctl restart iwd.service" + "on-click-right": "~/.local/bin/iwctl-re --mode=soft", + "on-click-middle": "~/.local/bin/iwctl-re --mode=hard" }, "battery": { "format": "E {capacity}%", diff --git a/.local/bin/iwctl-re b/.local/bin/iwctl-re index 4343b30..5fc494d 100755 --- a/.local/bin/iwctl-re +++ b/.local/bin/iwctl-re @@ -1,9 +1,40 @@ -#!/bin/zsh +#!/usr/bin/env python3 -notify-send "WLAN Reload" "Disconnect" -iwctl station wlan0 disconnect +import sys, os +import argparse +import subprocess +import time -sleep 5 -notify-send "WLAN Reload" "Reconnect" -iwctl --passphrase $(pass router/passphrase) station wlan0 connect "$(pass router/name)" $(pass router/security) +parser = argparse.ArgumentParser( + prog='iwctl-re' +) + +parser.add_argument( + '--mode', + default='soft', + choices=['soft', 'hard'] +) + +args = parser.parse_args() + + +def getSubprocessOutput(command): + return subprocess.run(command, capture_output=True, text=True).stdout.strip() + + +if args.mode == 'soft': + subprocess.run(['notify-send', 'WLAN Reload', 'Disconnect']) + subprocess.run(['iwctl', 'station', 'wlan0', 'disconnect']) + + time.sleep(5) + + subprocess.run(['notify-send', 'WLAN Reload', 'Reconnect']) + wlan_passphrase = getSubprocessOutput(['pass', 'router/passphrase']) + wlan_name = getSubprocessOutput(['pass', 'router/name']) + wlan_security = getSubprocessOutput(['pass', 'router/security']) + subprocess.run(['iwctl', '--passphrase', wlan_passphrase, 'station', 'wlan0', 'connect', wlan_name, wlan_security]) + +elif args.mode == 'hard': + subprocess.run(['notify-send', 'WLAN Reload', 'Restart iwd.service']) + subprocess.run(['sudo', 'systemctl', 'restart', 'iwd.service']) |