From 64234286f0b8bad30e685734f045a12c96e2baaa Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Thu, 18 Feb 2021 14:36:47 +0100 Subject: [PATCH] add function to determine windows wsl and a function to open links in Windows web browser if wsl is used --- settings/general-settings.el | 20 +++++++++++++------- settings/pre-settings.el | 8 ++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/settings/general-settings.el b/settings/general-settings.el index 263fcfa5..55127521 100644 --- a/settings/general-settings.el +++ b/settings/general-settings.el @@ -152,18 +152,14 @@ but it's REALLY SLOW when you have buffers that are visiting remote files. And despite its documentation, it does NOT ignore those files, if you're using windows, and the file name begins -with a drive letter and a colon.") - ) - (setq global-auto-revert-non-file-buffers t) - ) - ) +with a drive letter and a colon.")) + (setq global-auto-revert-non-file-buffers t))) (setq revert-without-query '(".*")) (use-package uniquify :defer t :config - (setq uniquify-buffer-name-style 'forward) ;; forward: bar/mumble/name insead of post-forward-angle-brackets: name - ) + (setq uniquify-buffer-name-style 'forward)) ;; forward: bar/mumble/name insead of post-forward-angle-brackets: name ;; overwrite selected text (delete-selection-mode t) @@ -217,6 +213,16 @@ with a drive letter and a colon.") ;; gravatars from magit use this to store their cache (setq url-configuration-directory (concat user-cache-directory "url/")) +;; https://adam.kruszewski.name/2017/09/emacs-in-wsl-and-opening-links/ +;; For WSL open links in Windows web browser of choice +(when running-on-windows-wsl + (let ((cmd-exe "/mnt/c/Windows/System32/cmd.exe") + (cmd-args '("/c" "start"))) + (when (file-exists-p cmd-exe) + (setq browse-url-generic-program cmd-exe + browse-url-generic-args cmd-args + browse-url-browser-function 'browse-url-generic)))) + (setq bookmark-default-file (concat user-cache-directory "bookmarks")) (use-package transient diff --git a/settings/pre-settings.el b/settings/pre-settings.el index 5033a60f..c1042d44 100644 --- a/settings/pre-settings.el +++ b/settings/pre-settings.el @@ -41,6 +41,14 @@ (memq system-type '(windows-nt cygwin32 cygwin)) "Non-nil if and only if we're running on Windows. Both Win32 and Cygwin count.") +;; https://stackoverflow.com/questions/60922620/shell-script-to-check-if-running-in-windows-when-using-wsl +(defvar running-on-windows-wsl + (string-equal + (replace-regexp-in-string + "[ \n]+$" "" + (shell-command-to-string + "uname -a | sed -n 's/.*\\( *Microsoft *\\).*/\\1/ip'")) + "Microsoft")) (setq user-emacs-directory "~/.config/emacs/") (defconst user-cache-directory (file-name-as-directory (concat user-emacs-directory ".cache"))