web.lisp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. (in-package :stumpwm)
  2. (defvar *browser* "firefox")
  3. (defvar *browser-name* "firefox-default")
  4. (defvar *jenkins-url*
  5. "https://jenkins.wugi.info")
  6. (defvar youtube-playlist-cool-music
  7. "PLmjgicsUWIkvEKkLN01vm85neXAik3yU2")
  8. (defun browse-url-firefox (url &optional new-window)
  9. (run-shell-command (join `("firefox" ,@(if new-window "--new-window" '())
  10. ,url))))
  11. (defun browse-url-firefox* (url &key (new-window t) title (theme 'dark) ssb)
  12. (let ((command (join `(,@(if (equal theme 'dark) '("GTK_THEME=Adwaita:dark") '())
  13. "firefox"
  14. ,@(if new-window '("--new-window") '())
  15. ,@(if ssb '("--ssb") '())
  16. ,url))))
  17. (if title
  18. (run-or-raise command `(:title ,title))
  19. (run-shell-command command))))
  20. (defcommand music-youtube () ()
  21. (let ((window (current-window)))
  22. (if (and window (string= (window-res window)
  23. "www.youtube.com__playlist"))
  24. (other-in-frame-or-fother)
  25. (run-or-raise (concat "chromium --app=https://www.youtube.com/playlist?list="
  26. youtube-playlist-cool-music)
  27. '(:instance "www.youtube.com")))))
  28. (defcommand jenkins () ()
  29. (browse-url-firefox* *jenkins-url*
  30. :title "Jenkins"))
  31. (defcommand youtube () ()
  32. (browse-url-firefox* "https://www.youtube.com/feed/subscriptions" t))
  33. (defcommand twitch-tome4 () ()
  34. (browse-url-firefox* "https://www.twitch.tv/directory/game/Tales%20of%20Maj'Eyal" t))
  35. (defcommand jenkins-index () ()
  36. (browse-url-firefox* *jenkins-url* "Jenkins"))
  37. (defcommand tometips () ()
  38. (run-shell-command "chromium --app=https://tometips.github.io"))
  39. (defcommand discord () ()
  40. (run-shell-command "chromium --app=https://discordapp.com/"))
  41. (defcommand jenkins-chromium () ()
  42. (run-or-raise (concat "chromium --app=" *jenkins-url*)
  43. '(:instance "jenkins")))
  44. (defcommand cuirass () ()
  45. (browse-url-firefox* "https://grafana.wugi.info/d/Ob67YJYiz/fiore?refresh=30s&orgId=1&var-host=cuirass"))
  46. (defcommand yoo (url) ((:string "YouTube URL: "))
  47. (gnew "youtube")
  48. (restore-group (current-group) (read-dump-from-file "/home/oleg/youtube.lisp"))
  49. (term-shell-command (format nil "mpv --no-resume-playback --mute=yes ~s" url))
  50. (browse-url-firefox* (format nil "https://www.youtube.com/live_chat?v=~a&is_popout=1"
  51. (cadr (split-string url "=")))
  52. t))
  53. (defcommand guix-ci () ()
  54. (browse-url-browse-url-firefox* "http://ci.guix.info/jobset/guix-master"))
  55. (defcommand guix-ci-package (package) ((:string "package: "))
  56. (unless (string= package "")
  57. (browse-url-browse-url-firefox*
  58. (concat "http://ci.guix.info/search?query=spec%3Aguix-master+system%3Ax86_64-linux+"
  59. package)
  60. t)))
  61. (defcommand jenkins-ci-wigust () ()
  62. (browse-url-browse-url-firefox* (format nil "~a/job/wigust/" *jenkins-url*)))
  63. (defcommand jenkins-ci-guix () ()
  64. (browse-url-browse-url-firefox* (format nil "~a/job/guix/" *jenkins-url*)))
  65. (defcommand repology-guix-outdated () ()
  66. (browse-url-browse-url-firefox* "https://repology.org/projects/?inrepo=gnuguix&outdated=1"))
  67. (defcommand twitch-channel-chat (channel) ((:string "channel: "))
  68. (run-shell-command
  69. (concat "chromium --app=https://www.twitch.tv/popout/"
  70. channel "/chat?popout=")))
  71. (defcommand youtube () ()
  72. "Open YouTube in Firefox."
  73. (run-shell-command "firefox --new-window https://www.youtube.com"))
  74. (defcommand w3m () ()
  75. "Open a W3M browser in user's home directory."
  76. (run-shell-command (join (list *xterm-command*
  77. *xterm-theme-light*
  78. *xterm-no-scrollbar*
  79. *term-execute-flag*
  80. (w3m "~")))))
  81. (defcommand irc-guix-log () ()
  82. "Open an IRC Guix log in `w3m'."
  83. (run-shell-command (join (list *xterm-command*
  84. *xterm-theme-light*
  85. *xterm-no-scrollbar*
  86. *term-execute-flag*
  87. (w3m "https://gnunet.org/bot/log/guix/")))))
  88. (defcommand browse-transmission () ()
  89. "Open transmissin WEB client."
  90. (run-shell-command (join (list *browser*
  91. (concat "http://torrent."
  92. *transmission-hostname* ".local")))))
  93. ;; Origin <https://github.com/alezost/stumpwm-config/blob/master/utils.lisp#L332>
  94. (defcommand browse-url (url) (:shell "Browse URL: ")
  95. "Browse URL with ‘*browser*’."
  96. (run-prog *browser* :args (list url) :wait nil :search t))
  97. (defcommand icecat () ()
  98. "Start or focus icecat."
  99. (run-or-raise "icecat" '(:class "IceCat")))
  100. (defcommand firefox-test () ()
  101. "Start of focus firefox."
  102. (run-shell-command (join (list (firefox-command) "-P" "test"))
  103. '(:class "firefox-default")))
  104. (defun firefox-temp-profile (&optional profile url)
  105. (join `("GTK_THEME=Adwaita:dark"
  106. ,*fontconfig-file*
  107. "firefox-temp-profile"
  108. ,@(if profile (list profile) '())
  109. ,@(if url (list url) '()))))
  110. (defun firefox-command (&optional args)
  111. (join (append (list "GTK_THEME=Adwaita:dark" *fontconfig-file* "firefox")
  112. args)))
  113. (defun mjru-open-account (account)
  114. (run-shell-command (join (list *fontconfig-file* "hms" "web" "open" account)))
  115. (run-shell-command (format nil "notify-send ~s"
  116. (format nil "Open account ~a in Firefox." account))))
  117. (defun mjru-open-billing2-account (account)
  118. (let ((url (run-shell-command
  119. (format nil "mjru-infa server | awk '/~a/ { print $NF }'" account) t)))
  120. (run-shell-command (format nil "firefox ~a" url))
  121. (run-shell-command
  122. (format nil "notify-send ~a"
  123. (format nil "Open account ~a in Firefox." url)))))
  124. (defcommand firefox () ()
  125. "Start of focus firefox."
  126. (run-or-raise (firefox-command) '(:class "firefox-default"))
  127. ;; (let ((clipboard (get-x-selection)))
  128. ;; (cond ((string-contains "AC_" clipboard)
  129. ;; (when (y-or-n-p (format nil "Open ~a account in firefox? " clipboard))
  130. ;; (sb-thread:make-thread
  131. ;; (lambda ()
  132. ;; (mjru-open-account clipboard)
  133. ;; (putsel "")))))
  134. ;; ((uiop/utility:string-prefix-p "mj" clipboard)
  135. ;; (when (y-or-n-p (format nil "Open ~a account in firefox? " clipboard))
  136. ;; (sb-thread:make-thread
  137. ;; (lambda ()
  138. ;; (mjru-open-billing2-account clipboard)
  139. ;; (putsel "")))))
  140. ;; ((uiop/utility:string-prefix-p "deprecated-web" clipboard)
  141. ;; (when (y-or-n-p (format nil "Open ~a account in firefox? " clipboard))
  142. ;; (sb-thread:make-thread
  143. ;; (lambda ()
  144. ;; (mjru-open-billing2-account
  145. ;; (last (split-string clipboard "-")))
  146. ;; (putsel "")))))
  147. ;; ((and (uiop/utility:string-prefix-p "u" clipboard)
  148. ;; (handler-case (parse-integer (subseq clipboard 1 (length clipboard))) (t (c) nil)))
  149. ;; (let ((account (concat "AC_" (subseq clipboard 1 (length clipboard)))))
  150. ;; (when (y-or-n-p (format nil "Open ~a account in firefox? " account))
  151. ;; (sb-thread:make-thread
  152. ;; (lambda ()
  153. ;; (mjru-open-account account)
  154. ;; (putsel ""))))))
  155. ;; ;; ((= (length clipboard) 24)
  156. ;; ;; (mjru-mongo-development-id-object))
  157. ;; (t (run-or-raise (firefox-command) '(:class "firefox-default")))))
  158. )
  159. (defcommand firefox-new-window () ()
  160. "Start Firefox."
  161. (let ((clipboard (get-x-selection)))
  162. (cond ((string-contains "AC_" clipboard)
  163. (when (y-or-n-p (format nil "Open ~a account in firefox? " clipboard))
  164. (sb-thread:make-thread
  165. (lambda ()
  166. (mjru-open-account clipboard)
  167. (putsel "")))))
  168. (t (run-shell-command
  169. (firefox-command '("--new-window")))))))
  170. (defcommand firefox-temp-profile-new-window () ()
  171. (run-shell-command (firefox-temp-profile)))
  172. (defcommand firefox-esr-52 () ()
  173. "Start of focus Firefox ESR 52."
  174. (run-shell-command "firefox-esr-52 --new-instance -P esr52"))
  175. (defun chromium-command (&optional command)
  176. (join `(,*fontconfig-file* "chromium" ,@command)))
  177. (defcommand chromium () ()
  178. "Start or focus Chromium."
  179. (run-or-raise (run-shell-command (chromium-command))
  180. '(:class "Chromium-browser")))
  181. (defcommand chromium-new-window () ()
  182. (run-shell-command (chromium-command '("--new-window"))))
  183. (defcommand chromium-app (url) ((:string "URL: "))
  184. "Start Chromium with app mode."
  185. (run-shell-command (chromium-command (list (concat "--app=" url)))))
  186. (defcommand chromium-proxy () ()
  187. "Start Chromium via proxy"
  188. (run-shell-command (concat "chromium"
  189. " --proxy-server='socks5://localhost:9050'"
  190. " --host-resolver-rules='MAP * ~NOTFOUND"
  191. " , EXCLUDE localhost'")))
  192. (defcommand spotify () ()
  193. (chromium-app "https://open.spotify.com"))
  194. (defcommand twitchy () ()
  195. (term-shell-command "twitchy"))
  196. (defcommand zabbix () ()
  197. (run-shell-command "firefox --new-window https://zabbix.wugi.info/"))
  198. (defcommand shop-food () ()
  199. (run-shell-command (join (list "shop" "--context" "food" (get-x-selection)))))
  200. ;;;
  201. ;;; Reference cards
  202. ;;;
  203. (defun browse-refcard (url)
  204. (run-shell-command (format nil "curl --silent ~s | zathura -" url)))
  205. (defcommand refcard-gnus () ()
  206. (browse-refcard "https://www.gnu.org/software/emacs/refcards/pdf/gnus-refcard.pdf"))
  207. ;;;
  208. ;;; Webhook
  209. ;;;
  210. (defcommand webhook () ()
  211. (run-shell-command (join (list "/home/oleg/.nix-profile/bin/webhook"
  212. "-hooks" "/home/oleg/.local/share/chezmoi/dotfiles/webhook/hooks.json"
  213. "-port" "9090"))))