#!/usr/bin/env bash

# /**
#  * Opens a URL or the local IP address on a connected KDE Connect device (Tablet).
#  *
#  * If a URL is provided as an argument, it sends it to the device.
#  * If no argument is provided, it detects the local network IP and shares it (port 42069).
#  *
#  * @param url Optional URL to open.
#  */

TABLET_ID="5d4ff2e96ea80ec1"

URL="$1"

if [ -n "$URL" ]; then
	kdeconnect-cli --share "$URL" -d $TABLET_ID
else
	MY_IP=$(ip addr show up | grep 'inet' | grep 'brd' | sed 's;^[^i]*inet \([0-9\.]*\)/[0-9]* brd [^$]*;\1;' | head -n 1)
	kdeconnect-cli --share $MY_IP:42069 -d $TABLET_ID
fi
