From 0fc501e04274a4de99cba69965a251e5c9048eda Mon Sep 17 00:00:00 2001 From: ChUrl Date: Wed, 26 Apr 2023 19:30:57 +0200 Subject: [PATCH] Add rofi vpn menu --- config/hyprland/hyprland.conf | 1 + config/rofi/menus/servers.txt | 1 + config/rofi/menus/systemd-podman.fish | 9 ++++----- config/rofi/menus/vpn.fish | 27 +++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 config/rofi/menus/servers.txt create mode 100755 config/rofi/menus/vpn.fish diff --git a/config/hyprland/hyprland.conf b/config/hyprland/hyprland.conf index cdc543fa..94603364 100644 --- a/config/hyprland/hyprland.conf +++ b/config/hyprland/hyprland.conf @@ -176,6 +176,7 @@ bind = $mainMod, D, exec, ~/NixFlake/config/rofi/menus/systemd-podman.fish bind = $mainMod, escape, exec, ~/NixFlake/config/rofi/menus/power.fish bind = $mainMod, O, exec, ~/NixFlake/config/rofi/menus/lectures.fish bind = $mainMod, M, exec, ~/NixFlake/config/rofi/menus/keybinds.fish +bind = $mainMod, U, exec, ~/NixFlake/config/rofi/menus/vpn.fish # Launch apps bind = $mainMod, T, exec, kitty diff --git a/config/rofi/menus/servers.txt b/config/rofi/menus/servers.txt new file mode 100644 index 00000000..fc7c6d85 --- /dev/null +++ b/config/rofi/menus/servers.txt @@ -0,0 +1 @@ +DE-115 \ No newline at end of file diff --git a/config/rofi/menus/systemd-podman.fish b/config/rofi/menus/systemd-podman.fish index e1e2fcf6..b5f5a73a 100755 --- a/config/rofi/menus/systemd-podman.fish +++ b/config/rofi/menus/systemd-podman.fish @@ -15,11 +15,10 @@ if not contains $ACTION $ACTIONS end # Execute command -set COMMAND_ROOT "pkexec --user root systemctl $ACTION podman-$SERVICE.service" -set COMMAND_USER "systemctl $ACTION podman-$SERVICE.service" -set EVAL_RESULT "$(eval $COMMAND_USER)" +set COMMAND "systemctl $ACTION podman-$SERVICE.service" +set EVAL_RESULT "$(eval $COMMAND)" -# Display result if it exists -if test -n "$EVAL_RESULT" +if test $ACTION = "status" && test -n "$EVAL_RESULT" + # Display result if it exists rofi -theme ~/NixFlake/config/rofi/rofi.rasi -e "$EVAL_RESULT" end diff --git a/config/rofi/menus/vpn.fish b/config/rofi/menus/vpn.fish new file mode 100755 index 00000000..bcb33790 --- /dev/null +++ b/config/rofi/menus/vpn.fish @@ -0,0 +1,27 @@ +#!/usr/bin/env fish + +# User chooses VPN server +set SERVERS (cat ~/NixFlake/config/rofi/menus/servers.txt) # TODO: This file should probably be generated by nix? +set SERVER (echo -e (string join "\n" $SERVERS) | rofi -theme ~/NixFlake/config/rofi/rofi.rasi -dmenu -p "vpn" -i) +if not contains $SERVER $SERVERS + exit +end + +# User chooses action +set ACTIONS "start" "stop" "status" +set ACTION (echo -e (string join "\n" $ACTIONS) | rofi -theme ~/NixFlake/config/rofi/rofi.rasi -dmenu -p "action" -i) +if not contains $ACTION $ACTIONS + exit +end + +# Enable wireguard netdev +set COMMAND "systemctl $ACTION wg0-$SERVER.service" +set EVAL_RESULT "$(eval $COMMAND)" + +if test $ACTION = "status" && test -n "$EVAL_RESULT" + # Display result if it exists + rofi -theme ~/NixFlake/config/rofi/rofi.rasi -e "$EVAL_RESULT" +else if test $ACTION = "start" + # Launch chromium in firejail + firejail --noprofile --netns=vpn chromium --incognito ipaddress.my &>/dev/null +end