095d56b5ea44988c83d0be501e70f37df3d5066b

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Fix WSL check for WSL 2 and simplify nohup in open_command

WSL 2 changes the output of `uname -r`. For instance,

  WSL 1: 4.4.0-18980-Microsoft
  WSL 2: 4.19.67-microsoft-standard

Since WSL 2 lowercases the M, we can match for the rest of the string
which remains lowercase throughout both versions. Another option would
be to match for both upper- and lower-case Ms, like that:

  $(uname -r) = *[Mm]icrosoft*

Fixed use of nohup in open_command where it was only necessary for
xdg-open (and actually harmful for cmd.exe in WSL 2). The current logic
is simpler and more future-proof.

Diff

 1diff --git a/lib/functions.zsh b/lib/functions.zsh
 2index 9f8736bd7e2967321fd95b561a5480f5c5d42e5e..61dfa478009beb5832cc06986b50be7554832440 100644
 3--- a/lib/functions.zsh
 4+++ b/lib/functions.zsh
 5@@ -21,7 +21,7 @@ function open_command() {
 6   case "$OSTYPE" in
 7     darwin*)  open_cmd='open' ;;
 8     cygwin*)  open_cmd='cygstart' ;;
 9-    linux*)   ! [[ $(uname -a) =~ "Microsoft" ]] && open_cmd='xdg-open' || {
10+    linux*)   [[ "$(uname -r)" != *icrosoft* ]] && open_cmd='nohup xdg-open' || {
11                 open_cmd='cmd.exe /c start ""'
12                 [[ -e "$1" ]] && { 1="$(wslpath -w "${1:a}")" || return 1 }
13               } ;;
14@@ -31,12 +31,7 @@ function open_command() {
15               ;;
16   esac
17 
18-  # don't use nohup on OSX
19-  if [[ "$OSTYPE" == darwin* ]]; then
20-    ${=open_cmd} "$@" &>/dev/null
21-  else
22-    nohup ${=open_cmd} "$@" &>/dev/null
23-  fi
24+  ${=open_cmd} "$@" &>/dev/null
25 }
26 
27 #
28diff --git a/plugins/sublime/sublime.plugin.zsh b/plugins/sublime/sublime.plugin.zsh
29index 3a82d6c7fa8018a399aeae207b38a0fcdd11a991..69604ab4f13f50a77cc2f63579bb695b8b849b4c 100644
30--- a/plugins/sublime/sublime.plugin.zsh
31+++ b/plugins/sublime/sublime.plugin.zsh
32@@ -15,7 +15,7 @@ alias stn=create_project
33   declare -a _sublime_paths
34 
35   if [[ "$OSTYPE" == linux* ]]; then
36-    if [[ "$(uname -r)" = *Microsoft* ]]; then
37+    if [[ "$(uname -r)" = *icrosoft* ]]; then
38       _sublime_paths=(
39         "$(wslpath -u 'C:\Program Files\Sublime Text 3\subl.exe')"
40         "$(wslpath -u 'C:\Program Files\Sublime Text 2\subl.exe')"