diff options
| author | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
| commit | 0860db73ae6fd9a6f6347219d820bf026a6b8b91 (patch) | |
| tree | 11318c3670d1c32c5aa0bf404c22fba3bf63fc53 /bin/vpnm | |
| parent | 4e34cbf9673aeaba252e01df554a0d204e83c5e2 (diff) | |
| download | dotfiles-master.tar.gz | |
Automated-commit-by: dots Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
| -rwxr-xr-x | bin/vpnm | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/bin/vpnm b/bin/vpnm index f09b41a..0fe1224 100755 --- a/bin/vpnm +++ b/bin/vpnm @@ -12,9 +12,17 @@ main() { local conn conn=$(get_current_connection) - [ -n "$conn" ] && fuzl_action_add "down" "" "Connected to $conn" + [ -n "$conn" ] && fuzl_action_add "exitnode_down" "" "Connected to $conn" fuzl_action_add "networks" "" "Available networks" - fuzl_action_add "profile" "" "Switch profile" + + profile=$(ts_profile_current) + fuzl_action_add "profile" "" "Profile: $profile" + + if ts_state; then + fuzl_action_add "down" "" "Disable tailscale" + else + fuzl_action_add "up" "" "Enable tailscale" + fi fuzl_action_menu || return } @@ -23,6 +31,23 @@ main() { # helpers # +ts_state() { + tailscale wait --timeout=1s +} +ts_profile_list() { + fuzl_try -- tailscale switch --list --json +} +ts_profile_current() { + ts_profile_list | jq -rc '.[]|select(.selected)|.nickname' +} +ts_profile_switch() { + local profile=${1?} + fuzl_try -- tailscale switch "$profile" + sleep 2 + fuzl_try -- pkill -SIGRTMIN+2 waybar + +} + get_emoji_flag() { code= # TODO: calc flag @@ -68,18 +93,17 @@ get_vpn_connections() { get_current_connection() { tailscale exit-node list | grep -e selected | - grep -v -e Any | ( - awk '/.tail2d6ce.ts.net/{print $2, $1}' - awk -F '[ ]{2,}' '/.mullvad.ts.net/{print $2, $1, ($3 "/" $4)}' - ) | while read -r conn ip location; do - printf '%s' "$(get_emoji_flag "$conn")" - printf ' ' - if grep -q 'mullvad.ts.net' <<<"$conn"; then - printf '%s' "$location" - else - printf '%s' "$conn" - fi - done + grep -v -e Any | + awk -F '[ ]{2,}' '/.mullvad.ts.net/{print $2, $1, ($3 "/" $4)} /.tail2d6ce.ts.net/{print $2, $1}' | + while read -r conn ip location; do + printf '%s' "$(get_emoji_flag "$conn")" + printf ' ' + if grep -q 'mullvad.ts.net' <<<"$conn"; then + printf '%s' "$location" + else + printf '%s' "$conn" + fi + done } vpnup() { @@ -96,7 +120,7 @@ vpndown() { # actions # -vpnm_down() { +vpnm_exitnode_down() { fuzl_try -- vpndown } @@ -110,15 +134,21 @@ vpnm_networks() { } vpnm_profile() { - profile=$(tailscale switch --list 2>/dev/null | - tail -n+2 | - awk '{printf "%s\t%s\n", $3, $2}' | - fuzl_menu $FUZL_MENU_FILTER --accept-nth=1) + profile=$( + ts_profile_list | + jq -rc '.[]|"\(.nickname)\t\(.tailnet)\t\(if .selected then "*" else "" end)"' | + fuzl_menu $FUZL_MENU_FILTER --accept-nth=1 + ) [ -n "$profile" ] || main - fuzl_try -- tailscale switch "$profile" - sleep 2 - fuzl_try -- pkill -SIGRTMIN+2 waybar + ts_profile_switch "$profile" +} + +vpnm_up() { + fuzl_try -- tailscale up +} +vpnm_down() { + fuzl_try -- tailscale down } main |