dots/configs/fish/functions/ssh-tunnel.fish
2026-01-30 16:45:03 -03:00

28 lines
1,004 B
Fish

function ssh-tunnel
set -l label "Select SSH tunnel to activate:"
set -l tunnel (fd . ~/.ssh/tunnels.d/ | fzf -d / --with-nth=6 --accept-nth=6 --nth=6 --preview='bat {}' --input-label=foo --input-label-pos=bottom | cut -d "." -f 1)
if test -z $tunnel
return
end
envsource "$HOME/.ssh/tunnels.d/$tunnel.conf" > /dev/null
echo "Activating connection $tunnel..."
if not systemctl --user is-active "database-ssh-tunnel@$tunnel.service" -q
systemctl --user start "database-ssh-tunnel@$tunnel.service"
end
if test (string lower $DB_START_EXPLORER) = "true"
echo "Opening Databse in browser, password will be copied to the clipboard..."
if not systemctl --user is-active "dev-dbui.service" -q
systemctl --user start "dev-dbui.service"
end
wl-copy "$DB_PASSWORD"
xdg-open "http://localhost:8080?$DB_DRIVER=$TUNNEL_LOCAL_ADDRESS:$TUNNEL_LOCAL_PORT&username=$DB_USER&db=$DB_NAME&ns=public"
end
end