~ruther/guix-config

549611bbfd4ac137cd89a9fe65bbc1ed4273b98d — Rutherther 9 days ago 2f51770
feat: add browser-selector.desktop for opening different browsers
M home/home-configuration.scm => home/home-configuration.scm +1 -0
@@ 172,6 172,7 @@
     ;; Browsing
     "librewolf"
     "firefox" ;; No netflix in librewolf :'(
     "browser-selector"

     ;; Development
     "git" "openssh"

A home/modules/ruther/packages/browser-selector-script => home/modules/ruther/packages/browser-selector-script +43 -0
@@ 0,0 1,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)))

A home/modules/ruther/packages/browser-selector.scm => home/modules/ruther/packages/browser-selector.scm +40 -0
@@ 0,0 1,40 @@
(define-module (ruther packages browser-selector)
  #:use-module (guix packages)
  #:use-module (guix build-system copy)
  #:use-module (guix gexp)
  #:use-module (guix licenses)
  #:use-module (gnu packages guile))

(define-public browser-selector
  (package
    (name "browser-selector")
    (version "1.0")
    (source (local-file "browser-selector-script"))
    (build-system copy-build-system)
    (arguments
     '(#:install-plan
       '(("browser-selector-script" "bin/browser-selector"))
       #:phases
       (modify-phases %standard-phases
         (add-after 'install 'make-executable
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((bin-file (string-append (assoc-ref outputs "out")
                                            "/bin/browser-selector")))
               (chmod bin-file #o755))))
         (add-after 'make-executable 'install-desktop-file
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out")))
               (make-desktop-entry-file
                (string-append out "/share/applications/browser-selector.desktop")
                #:name "Browser Selector"
                #:comment "Smart browser selector for URLs"
                #:exec (string-append out "/bin/browser-selector %u")
                #:categories '("Network" "WebBrowser")
                #:mime-type '("text/html" "text/xml" "application/xhtml+xml" "x-scheme-handler/http" "x-scheme-handler/https"))))))))
    (native-inputs (list guile-3.0))
    (home-page "")
    (synopsis "Smart browser selector for URLs")
    (description "A Guile script that automatically selects Firefox or LibreWolf
based on URL patterns.  YouTube, Netflix, Max, Twitch, and Discord open in
Firefox, while all other URLs open in LibreWolf.")
    (license gpl3+)))