#!/usr/bin/env guile
!#
(use-modules (ice-9 regex)
(srfi srfi-1))
(define firefox-patterns
'("youtu\\.be"
"youtube\\.com"
"netflix\\.com"
"max\\.com"
"twitch\\.tv"
"discord\\.com"))
(define (matches-pattern? url patterns)
"Check if URL matches any pattern in the list"
(any (lambda (pattern)
(string-match pattern url))
patterns))
(define (get-browser-for-url url)
"Determine which browser to use for the given URL"
(if (matches-pattern? url firefox-patterns)
"firefox"
"librewolf"))
(define (open-url url)
"Open URL with the appropriate browser"
(let ((browser (get-browser-for-url url)))
(format #t "Opening ~a with ~a~%" url browser)
(system (string-append browser " '" url "' &"))))
(define (main args)
"Main function"
(if (< (length args) 2)
(begin
(format #t "Usage: ~a <url>~%" (car args))
(exit 1))
(let ((url (cadr args)))
(open-url url))))
(when (batch-mode?)
(main (command-line)))