From 9794a376831e8a34d4b5df05894149f9bcbcabbc Mon Sep 17 00:00:00 2001 From: Thomas Dehaeze Date: Sun, 15 Nov 2020 19:02:51 +0100 Subject: [PATCH] Add toggle connection (wifi/ethernet) --- polybar.org | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/polybar.org b/polybar.org index 8d94784..e89f659 100644 --- a/polybar.org +++ b/polybar.org @@ -773,12 +773,12 @@ #+begin_src conf [module/wired-network] type = internal/network - interface = enp0s20f0u6u4 + interface = ens12u2u4u4 - label-connected =  %local_ip% + label-connected = %{A1:bash ~/.config/polybar/scripts/connection-toggle.sh ens12u2u4u4 >/dev/null 2>%1 &:} %local_ip%%{A} label-connected-foreground = ${colors.fg} - label-disconnected =  + label-disconnected = %{A1:bash ~/.config/polybar/scripts/connection-toggle.sh ens12u2u4u4 >/dev/null 2>%1 &:}%{A} label-disconnected-foreground = #777 #+end_src @@ -790,13 +790,41 @@ format-connected = format-disconnected = - label-connected = 直 %essid% + label-connected = %{A1:bash ~/.config/polybar/scripts/connection-toggle.sh wlp2s0 >/dev/null 2>%1 &:}直 %essid%%{A} label-connected-foreground = ${colors.fg} - label-disconnected = 睊 + label-disconnected = %{A1:bash ~/.config/polybar/scripts/connection-toggle.sh wlp2s0 >/dev/null 2>%1 &:}直%{A} label-disconnected-foreground = #777 #+end_src +** Toggle Wifi or Ethernet +:PROPERTIES: +:header-args: :tangle ~/.config/polybar/scripts/connection-toggle.sh +:header-args+: :comments both :mkdirp yes +:header-args+: :shebang "#!/usr/bin/env bash" +:END: + +#+begin_src bash + # Check if an argument is passed + if [ -z "$1" ] + then + exit 1 + fi + + isdevicedown=$(nmcli device status | grep ^$1 | grep disconnected) + + if [ -z "$isdevicedown" ] + then + dunstify --replace=84847 "$1" "Disconnecting..." && \ + nmcli device disconnect $1 && \ + dunstify --replace=84847 "$1" "Disconnected" + else + dunstify --replace=84847 "$1" "Connection..." && \ + nmcli device connect $1 && \ + dunstify --replace=84847 "$1" "Connected" + fi +#+end_src + * Wireguard #+BEGIN_SRC conf [module/wireguard]