Skip to content

Instantly share code, notes, and snippets.

@nixmaniack
Created March 4, 2016 10:43
Show Gist options
  • Save nixmaniack/0d8a7ebb0cf77c5690e8 to your computer and use it in GitHub Desktop.
Save nixmaniack/0d8a7ebb0cf77c5690e8 to your computer and use it in GitHub Desktop.
Open in appropriate browser based on URL
(setq
browse-url-chromium-program "/opt/homebrew-cask/Caskroom/google-chrome/latest/Google Chrome.app/Contents/MacOS/Google Chrome"
browse-url-firefox-program "/opt/homebrew-cask/Caskroom/firefox/41.0.1/Firefox.app/Contents/MacOS/firefox")
(defun my-browse-url-maybe-privately (url &optional new-window)
"Ask whether URL should be browsed in a private browsing window."
(interactive "sURL: ")
(if (y-or-n-p "Private Browsing? ")
(my-browse-url-chrome-privately url)
(browse-url-default-browser url new-window)))
(defun my-browse-url-chrome-privately (url &optional new-window)
"Make firefox open URL in private-browsing window."
(interactive (browse-url-interactive-arg "URL: "))
(let ((process-environment (browse-url-process-environment)))
(apply 'start-process
(concat "chrome " url)
nil
browse-url-chromium-program
(list "--incognito" url))))
(setq browse-url-browser-function
'(("^https?://t\\.co" . my-browse-url-chrome-privately)
("^https?://instagram\\.com" . my-browse-url-chrome-privately)
("^https?://github\\.com/PrivateRepo" . browse-url-default-browser)
("^https?://github\\.com" . my-browse-url-maybe-privately)
("." . my-browse-url-maybe-privately)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment