Add toggle connection (wifi/ethernet)

This commit is contained in:
Thomas Dehaeze 2020-11-15 19:02:51 +01:00
parent 69b4e979c3
commit 6501e49fb9

View File

@ -773,12 +773,12 @@
#+begin_src conf #+begin_src conf
[module/wired-network] [module/wired-network]
type = internal/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-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 label-disconnected-foreground = #777
#+end_src #+end_src
@ -790,13 +790,41 @@
format-connected = <label-connected> format-connected = <label-connected>
format-disconnected = <label-disconnected> format-disconnected = <label-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-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 label-disconnected-foreground = #777
#+end_src #+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 * Wireguard
#+BEGIN_SRC conf #+BEGIN_SRC conf
[module/wireguard] [module/wireguard]