f898ada8e3d25c7d1ea309b487711a4e0a2c07b6

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

Message

open_command: fix and improve command for WSL

- Add double quotes to command so that the next argument isn't
  interpreted as the title for the start command.

- If the first argument is a valid path, convert it to Windows path
  notation. If `wslpath` fails—because it's a path from inside WSL,
  which cannot be converted to Windows path notation— fail with an
  error code.

  This last circumstance will show an error like so:

    wslpath: path: Result not representable

Diff

 1diff --git a/lib/functions.zsh b/lib/functions.zsh
 2index f448dbce81dba1090c061e71a944d392d7ad0897..dd8311611eb9be1f3e460adb0c2a80e229f16bf7 100644
 3--- a/lib/functions.zsh
 4+++ b/lib/functions.zsh
 5@@ -22,9 +22,10 @@ function open_command() {
 6   case "$OSTYPE" in
 7     darwin*)  open_cmd='open' ;;
 8     cygwin*)  open_cmd='cygstart' ;;
 9-    linux*)   [[ $(uname -a) =~ "Microsoft" ]] && \
10-                open_cmd='cmd.exe /c start' || \
11-                open_cmd='xdg-open' ;;
12+    linux*)   ! [[ $(uname -a) =~ "Microsoft" ]] && open_cmd='xdg-open' || {
13+                open_cmd='cmd.exe /c start ""'
14+                [[ -e "$1" ]] && { 1="$(wslpath -w "${1:a}")" || return 1 }
15+              } ;;
16     msys*)    open_cmd='start ""' ;;
17     *)        echo "Platform $OSTYPE not supported"
18               return 1