From 2a37cdd6dab3306700a9708e5bf3f6d5884284de Mon Sep 17 00:00:00 2001 From: Anish Lakhwara Date: Sun, 8 Sep 2024 16:32:25 -0700 Subject: [PATCH] add vpn script --- home/darwin/sketchybar/items/vpn.sh | 4 ++ home/darwin/sketchybar/plugins/vpn.sh | 16 +++++++ home/darwin/sketchybar/plugins/wg_off.sh | 5 +++ home/darwin/sketchybar/plugins/wg_on.sh | 5 +++ hosts/darwin/casks/default.nix | 1 + hosts/darwin/sketchybar/sketchybarrc | 55 ++++++++++++------------ 6 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 home/darwin/sketchybar/items/vpn.sh create mode 100644 home/darwin/sketchybar/plugins/vpn.sh create mode 100644 home/darwin/sketchybar/plugins/wg_off.sh create mode 100644 home/darwin/sketchybar/plugins/wg_on.sh diff --git a/home/darwin/sketchybar/items/vpn.sh b/home/darwin/sketchybar/items/vpn.sh new file mode 100644 index 00000000..2c640c90 --- /dev/null +++ b/home/darwin/sketchybar/items/vpn.sh @@ -0,0 +1,4 @@ +sketchybar -m --add item vpn right \ + --set vpn icon= \ + update_freq=5 \ + script="~/.config/sketchybar/plugins/vpn.sh" diff --git a/home/darwin/sketchybar/plugins/vpn.sh b/home/darwin/sketchybar/plugins/vpn.sh new file mode 100644 index 00000000..8b71a6e2 --- /dev/null +++ b/home/darwin/sketchybar/plugins/vpn.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +### You need to edit sudoers file to run wg-quick without password + +# %admin ALL = (ALL) NOPASSWD: /nix/store/s2qw0sxax8pckbzmyw6wrarahmx65bq9-wireguard-tools-1.0.20210914/bin/wg-quick + +WG_PIDFILE="/var/run/wireguard/wg0.name" + +if [ -f $WG_PIDFILE ]; then + sketchybar -m --set vpn icon= \ + label="$VPN" \ + drawing=on \ + click_script="~/.config/sketchybar/plugins/wg_off.sh" +else + sketchybar -m --set vpn drawing=off click_script="~/.config/sketchybar/plugins/wg_on.sh" +fi diff --git a/home/darwin/sketchybar/plugins/wg_off.sh b/home/darwin/sketchybar/plugins/wg_off.sh new file mode 100644 index 00000000..8d9713e0 --- /dev/null +++ b/home/darwin/sketchybar/plugins/wg_off.sh @@ -0,0 +1,5 @@ +### You need to edit sudoers file to run wg-quick without password + +# %admin ALL = (ALL) NOPASSWD: /nix/store/s2qw0sxax8pckbzmyw6wrarahmx65bq9-wireguard-tools-1.0.20210914/bin/wg-quick + +sudo wg-quick down wg0 diff --git a/home/darwin/sketchybar/plugins/wg_on.sh b/home/darwin/sketchybar/plugins/wg_on.sh new file mode 100644 index 00000000..532ca0ad --- /dev/null +++ b/home/darwin/sketchybar/plugins/wg_on.sh @@ -0,0 +1,5 @@ +### You need to edit sudoers file to run wg-quick without password + +# %admin ALL = (ALL) NOPASSWD: /nix/store/s2qw0sxax8pckbzmyw6wrarahmx65bq9-wireguard-tools-1.0.20210914/bin/wg-quick + +sudo wg-quick up wg0 diff --git a/hosts/darwin/casks/default.nix b/hosts/darwin/casks/default.nix index bb321aca..e645495e 100644 --- a/hosts/darwin/casks/default.nix +++ b/hosts/darwin/casks/default.nix @@ -29,6 +29,7 @@ # "slack" # "zoom" # "firefox" + # "1password-cli" # Utility Tools # "syncthing" diff --git a/hosts/darwin/sketchybar/sketchybarrc b/hosts/darwin/sketchybar/sketchybarrc index cecc054d..775c7141 100755 --- a/hosts/darwin/sketchybar/sketchybarrc +++ b/hosts/darwin/sketchybar/sketchybarrc @@ -4,35 +4,35 @@ source "$HOME/.config/sketchybar/variables.sh" # Loads all defined colors # General bar and defaults # parts I didn't want - # y_offset=5 \ - # margin=5 \ +# y_offset=5 \ +# margin=5 \ sketchybar --bar height=35 \ - color="$BAR_COLOR" \ - shadow="$SHADOW" \ - position=top \ - sticky=on \ - padding_right=0 \ - padding_left=3 \ - corner_radius="$CORNER_RADIUS" \ - blur_radius=20 \ - notch_width=200 \ - --default updates=when_shown \ - icon.font="$FONT:Bold:13.5" \ - icon.color="$ICON_COLOR" \ - icon.padding_left="$PADDINGS" \ - icon.padding_right="$PADDINGS" \ - label.font="$FONT:Bold:13.0" \ - label.color="$LABEL_COLOR" \ - label.padding_left="$PADDINGS" \ - label.padding_right="$PADDINGS" \ - background.padding_right="$PADDINGS" \ - background.padding_left="$PADDINGS" \ - popup.background.border_width=1 \ - popup.background.corner_radius=11 \ - popup.background.border_color="$POPUP_BORDER_COLOR" \ - popup.background.color="$POPUP_BACKGROUND_COLOR" \ - popup.background.shadow.drawing="$SHADOW" + color="$BAR_COLOR" \ + shadow="$SHADOW" \ + position=top \ + sticky=on \ + padding_right=0 \ + padding_left=3 \ + corner_radius="$CORNER_RADIUS" \ + blur_radius=20 \ + notch_width=200 \ + --default updates=when_shown \ + icon.font="$FONT:Bold:13.5" \ + icon.color="$ICON_COLOR" \ + icon.padding_left="$PADDINGS" \ + icon.padding_right="$PADDINGS" \ + label.font="$FONT:Bold:13.0" \ + label.color="$LABEL_COLOR" \ + label.padding_left="$PADDINGS" \ + label.padding_right="$PADDINGS" \ + background.padding_right="$PADDINGS" \ + background.padding_left="$PADDINGS" \ + popup.background.border_width=1 \ + popup.background.corner_radius=11 \ + popup.background.border_color="$POPUP_BORDER_COLOR" \ + popup.background.color="$POPUP_BACKGROUND_COLOR" \ + popup.background.shadow.drawing="$SHADOW" # Left # source "$ITEM_DIR/apple.sh" @@ -48,6 +48,7 @@ source "$ITEM_DIR/calendar.sh" source "$ITEM_DIR/battery.sh" source "$ITEM_DIR/volume.sh" source "$ITEM_DIR/cpu.sh" +source "$ITEM_DIR/vpn.sh" #################### Finalizing Setup ####################