mirror of https://git.sr.ht/~skiqqy/bin
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
778 B
43 lines
778 B
#!/usr/bin/env bash
|
|
# Launches my focal instance in surf, if it isnt already open
|
|
|
|
# Get XID of a procces by name
|
|
# Usage: xidof NAME
|
|
xidof()
|
|
{
|
|
local name
|
|
local pid
|
|
|
|
name="${1:-surf}"
|
|
mapfile -t pids < <(pidof "$name" | tr ' ' $'\n')
|
|
|
|
[ "${#pids}" -eq 0 ] && return 1
|
|
for pid in "${pids[@]}"
|
|
do
|
|
printf '%s ' "$(wmctrl -ulp | tr -s ' ' | grep "$pid" | cut -d" " -f 1)" 2> /dev/null
|
|
done
|
|
}
|
|
|
|
# Usage: get_surf_url XID
|
|
get_surf_url()
|
|
{
|
|
xprop -id "$1" _SURF_URI | sed -E 's|.*?"(.*)".*?|\1|g'
|
|
}
|
|
|
|
main()
|
|
{
|
|
url='notes.skiqqy.xyz' # dont prefix with http/s
|
|
|
|
for surf_xid in $(xidof surf)
|
|
do
|
|
test=$(get_surf_url "$surf_xid")
|
|
if [[ "$test" =~ ^http(s)?://$url(/.*)?$ ]]
|
|
then
|
|
echo "A session is already open"
|
|
return 1
|
|
fi
|
|
done
|
|
surf "https://$url"
|
|
}
|
|
|
|
main "$@"
|
|
|