~ruther/guix-config

ref: 549611bbfd4ac137cd89a9fe65bbc1ed4273b98d guix-config/home/modules/ruther/packages/browser-selector-script -rw-r--r-- 1.0 KiB
549611bb — Rutherther feat: add browser-selector.desktop for opening different browsers a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/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)))