about summary refs log tree commit diff
path: root/configs/shared/.emacs.d/wpc/google-stuff.el
diff options
context:
space:
mode:
Diffstat (limited to 'configs/shared/.emacs.d/wpc/google-stuff.el')
-rw-r--r--configs/shared/.emacs.d/wpc/google-stuff.el183
1 files changed, 183 insertions, 0 deletions
diff --git a/configs/shared/.emacs.d/wpc/google-stuff.el b/configs/shared/.emacs.d/wpc/google-stuff.el
new file mode 100644
index 000000000000..4f4fe635a362
--- /dev/null
+++ b/configs/shared/.emacs.d/wpc/google-stuff.el
@@ -0,0 +1,183 @@
+;;; google-stuff.el --- Working with Google infrastructure from Emacs -*- lexical-binding: t -*-
+;; Author: William Carroll <wpcarro@gmail.com>
+
+;;; Commentary:
+;; Some of this is just encoding my learnings as notes in Elisp format.
+
+;;; Code:
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Dependencies
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(require 'f)
+(require 'ivy-helpers)
+(require 'evil-leader)
+(require 'maybe)
+(require 'device)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Library
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; TODO: Ensure a consistent and deliberate usage of `defvar', `defconst', and
+;; `defcustom' across all Elisp modules.
+(defcustom google-stuff/install-kbds? t
+  "When t, install the keybindings defined herein.")
+
+;; Definitions as explained by the highly knowledgeable Matthew (i.e. mjo@)
+(defconst google-stuff/definitions
+  '(
+    ;; command-line tools
+    ("gcert"  . "Requests a CorpSSH certificate.")
+    ("glogin" . "SSO (i.e. Single Sign-On) cookie.")
+    ("googlenetworkaccess" . "Device certificate that gives users a certificate
+to access to the Google corp network.")
+    ("prodaccess" . "Sets up a LOAS session on Goobuntu.")
+    ;; general wtfs
+    ("LOAS" . "Distributed authentication service used by jobs in production and
+corp to authenticate each other. It's more efficient than SSL and works with
+Stubby.")
+    ))
+
+;; TODO: Straighten out fig, citc, google3 and have modules for each.
+
+;; TODO: Move this to a google3.el module.
+(defconst google-stuff/root
+  "/google/src/cloud/wpcarro"
+  "The root directory to access google3.")
+
+;; TODO: Find a fast way to generate this.
+(defconst google-stuff/citc-clients
+  '("auto-consult"
+    "ac-skeleton")
+  "A list of my active CitC clients.")
+
+
+;; TODO: Can this be sourced from ~/.g4d?
+(defconst google-stuff/citc-aliases
+  '(("escalations" . "/google3/corp/gtech/pto/tda/beacons_extension")
+    ("spewall_fe" . "/google3/alkali/apps/speakeasydashboard")
+    ("spewall_be" . "/google3/java/com/google/alkali/applications/speakeasydashboard")
+    ("spewall_protos" . "/google3/google/internal/alkali/applications/speakeasydashboard")
+    ("spewall_tests" . "/google3/javatests/com/google/alkali/applications/speakeasydashboard")
+    ("gti" . "/google3/experimental/engedu/gti/projects/week20190422/mtv/Team10")
+    ("authwf" . "/google3/customer_support/automation/workflow")
+    ("redwood" . "/google3/customer_support/kms/redwood/ui")
+    ("wf-fe" . "/google3/customer_support/kms/redwood/ui/client/components/item/workflow_editor")
+    ("ac" . "/google3/google/internal/alkali/applications/casesconsultservice")
+    ("ac-server" . "/google3/java/com/google/alkali/applications/casesconsultservice/server/")
+    ("ac-server (tests)" . "/google3/javatests/com/google/alkali/applications/casesconsultservice/server/"))
+  "Mapping of a label to commonly visited locations in Google3.")
+
+
+(defvar google-stuff/active-citc-client nil
+  "Currently active CitC client.")
+
+(defun google-stuff/depot-prefix ()
+  "Return the current prefix for //depot/google3."
+  (string/format "/google/src/cloud/wpcarro/%s/google3/"
+                 google-stuff/active-citc-client))
+
+(defun google-stuff/cs-url ()
+  "Return the code-search URL for the current buffer and line number."
+  (string/format "cs.corp.google.com/piper///depot/google3/%s?l=%s"
+                 (s-chop-prefix
+                  (google-stuff/depot-prefix)
+                  (buffer-file-name))
+                 (line-number-at-pos)))
+
+(defun google-stuff/copy-cs-url ()
+  "Copy the current file and line-position to the system clipboard."
+  (interactive)
+  (clipboard/copy (google-stuff/cs-url)))
+
+(defun google-stuff/open-buffer-in-cs ()
+  "Open the current file in Google's CodeSearch."
+  (interactive)
+  (shell-command
+   (string/format "google-chrome '%s'"
+                  (google-stuff/cs-url)
+                  (line-number-at-pos))))
+
+;; TODO: As a naming convention, should I prefer ivy or select? Or counsel?
+(defun google-stuff/select-citc-client ()
+  "Set `google-stuff/active-citc-client' with counsel."
+  (interactive)
+  (setq google-stuff/active-citc-client
+        (ivy-read "CitC Client: " google-stuff/citc-clients)))
+
+(defun google-stuff/remote-buffer? ()
+  "Return t if buffer is one accessed via Tramp."
+  (with-current-buffer (current-buffer)
+    (if (file-remote-p default-directory)
+        t
+      nil)))
+
+(defun google-stuff/jump-to-citc-alias ()
+  "Use `find-file' to open an alias registered in `google-stuff/citc-aliases'.
+When on a corporate laptop, remote connections are made using Tramp."
+  (interactive)
+  (when (maybe/nil? google-stuff/active-citc-client)
+    (call-interactively #'google-stuff/select-citc-client))
+  (ivy-helpers/kv
+   "Jump to CitC Alias: "
+   google-stuff/citc-aliases
+   (lambda (k v)
+     (->> v
+          ;; If I don't remove the leading slash, `f-join' won't return a valid
+          ;; path.
+          (s-chop-prefix "/")
+          (f-join google-stuff/root
+                  google-stuff/active-citc-client)
+          (s-prepend (if (device/work-laptop?) "/ssh:wpcarro@desktop:" ""))
+          find-file))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Stuff I learned reading go/emacs
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Fig
+;; TODO: Make sure there are Evil-compatible KBDs for `fig-status'.
+;; (require 'google-fig)
+
+;; This allows `find-file' handle "//depot/google3/devtools/editors/".
+(require 'p4-files)
+(p4-enable-file-name-handler)
+
+;; Blaze Support
+;; - `google3-compile-current-file' is an excellent command!
+
+;; google3-eglot (uses CiderLSP)
+;; TODO: Make sure the functionality is supported as advertised:
+;; - auto-completion
+;; - eglot-help-at-point for documentation.
+;; - goto-definition
+;; - `eglot-code-actions' fixits
+;; - `eglot-rename' refactoring
+(require 'google3-eglot)
+(google3-eglot-setup)
+
+;; CodeSearch
+;; TODO: Debug why this depends on google-piper and why I don't have that on my
+;; desktop.
+;; (require 'ivy-cs)
+
+;; Auto completion
+;; TODO: Is the part of or separate from google3-eglot?  Because google3-eglot
+;; advertises auto-completion support.
+(require 'google3-build-capf)
+(google3-build-capf-enable-completions)
+(add-to-list 'company-backends #'company-capf)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Keybindings
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(when google-stuff/install-kbds?
+  (evil-leader/set-key "Gs" #'fig-status)
+  (evil-leader/set-key "Cs" #'google-stuff/open-buffer-in-cs)
+  (evil-leader/set-key "jc" #'google-stuff/jump-to-citc-alias))
+
+(provide 'google-stuff)
+;;; google-stuff.el ends here