about summary refs log tree commit diff
path: root/configs/shared/.emacs.d/wpc/chrome.el
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2019-10-09T11·13+0100
committerWilliam Carroll <wpcarro@gmail.com>2019-12-24T15·21+0000
commit6b456c1b7a4f6899f063a6e65355af51901d9c7a (patch)
treecfc70d74818ae9fabdbbfb0cf16cce092e4c1a09 /configs/shared/.emacs.d/wpc/chrome.el
parenta7c72adb2ebec1e497fc040eaf3551d564d61a5b (diff)
Massive configuration overhaul
Currently paying the price of months of non-diligent git usage.

Here's what has changed.

- Theming support in Gvcci and wpgtk
- Dropping support for i3
- Supporting EXWM
- Many Elisp modules
- Collapsed redundant directories in ./configs
Diffstat (limited to 'configs/shared/.emacs.d/wpc/chrome.el')
-rw-r--r--configs/shared/.emacs.d/wpc/chrome.el78
1 files changed, 78 insertions, 0 deletions
diff --git a/configs/shared/.emacs.d/wpc/chrome.el b/configs/shared/.emacs.d/wpc/chrome.el
new file mode 100644
index 000000000000..a27c9dd3967f
--- /dev/null
+++ b/configs/shared/.emacs.d/wpc/chrome.el
@@ -0,0 +1,78 @@
+;;; chrome.el --- Helpers for Google Chrome -*- lexical-binding: t -*-
+;; Author: William Carroll <wpcarro@gmail.com>
+
+;;; Commentary:
+;; Some helper functions for working with Google Chrome.
+
+;;; Code:
+
+(require 'macros)
+(require 'alist)
+(require 'list)
+
+(defvar chrome/install-kbds? t
+  "If t, install keybinding.")
+
+;; TODO: Consider modelling this as a rose-tree that can nest itself
+;; arbitrarily.
+;; TODO: Consider exporting existing chrome bookmarks.
+(defconst chrome/label->url
+  '(("Google" . "www.google.com")
+    ("Hacker News" . "news.ycombinator.com")
+    ("Gmail" . "www.gmail.com")
+    ("WhatsApp" . "web.whatsapp.com")
+    ("Google Chat" . "chat/")
+    ("Google Calendar" . "calendar/")
+    ("Teknql" . "teknql.slack.com/messages")
+    ("Twitter" . "twitter.com"))
+  "Mapping labels to urls for my bookmarks.")
+
+(defconst chrome/splash-pages
+  '("Google Calendar"
+    "Gmail"
+    "Google Chat"
+    "WhatsApp"
+    "Teknql")
+  "The pages that should open when I open Chrome.")
+
+;; TODO: Add defensive check to start chrome if it isn't already open.
+
+;; TODO: Support option to create new session even if one already exists.
+
+(defun chrome/open-splash-pages ()
+  "Opens Chrome with my preferred splash pages."
+  (interactive)
+  (->> chrome/splash-pages
+       (-map (lambda (x) (alist/get x chrome/label->url)))
+       chrome/open-urls))
+
+;; TODO: Support optional kwargs.
+(cl-defun chrome/open-url (url &keys new-window?)
+  "Opens `URL' in google-chrome.
+Will open without toolbars if APP-MODE? is t."
+  (shell-command (s-concat
+                  "google-chrome "
+                  (if new-window? "--new-window " "")
+                  url)))
+
+(defun chrome/open-urls (urls)
+  "Open multiple `URLS' in chrome."
+  (chrome/open-url
+   (list/join " " urls)))
+
+(defun chrome/browse ()
+  "Display a counsel window for browsing URLs."
+  (interactive)
+  (ivy-read
+   "URL: "
+   chrome/label->url
+   :action (lambda (entry)
+             (chrome/open-url (cdr entry)))))
+
+(when chrome/install-kbds?
+  (evil-leader/set-key
+    "cb" #'chrome/browse
+    "cs" #'chrome/open-splash-pages))
+
+(provide 'chrome)
+;;; chrome.el ends here