executable_xdg-open 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env -S guile --no-auto-compile -e main -s
  2. !#
  3. (use-modules (srfi srfi-1)
  4. (ice-9 format)
  5. (web uri))
  6. (define xdg-open
  7. "/run/current-system/profile/bin/xdg-open")
  8. (define (notify str)
  9. (system (format #f "notify-send ~s" str)))
  10. (define (main args)
  11. (let ((arg (last args)))
  12. (if (string-prefix? "http" arg)
  13. (let* ((uri (string->uri arg))
  14. (host (uri-host uri)))
  15. (cond
  16. ((string-prefix? host "imgur.com")
  17. (notify (format #f "Open in feh ~a" arg))
  18. (system (format #f "curl --silent ~s | feh -"
  19. (uri->string (build-uri 'https
  20. #:host (string-append "i." host)
  21. #:path (uri-path uri))))))
  22. ((string-prefix? host "cdn.discordapp.com")
  23. (notify (format #f "Open in feh ~a" arg))
  24. (system (format #f "curl --silent ~s | feh -" arg)))
  25. ((or (string-prefix? host "www.twitch.tv")
  26. (string-contains host "youtube.com"))
  27. (notify (format #f "Open in mpv ~a" arg))
  28. (system (format #f "mpv ~s" arg)))
  29. (else (execl "/run/current-system/profile/bin/xdg-open" "xdg-open" arg))))
  30. (execl "/run/current-system/profile/bin/xdg-open" "xdg-open" arg))))