Skip to content

Commit

Permalink
open_command: fix and improve command for WSL
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mcornella committed Jun 30, 2018
1 parent 004461d commit 0c1dfb4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function open_command() {
case "$OSTYPE" in
darwin*) open_cmd='open' ;;
cygwin*) open_cmd='cygstart' ;;
linux*) [[ $(uname -a) =~ "Microsoft" ]] && \
open_cmd='cmd.exe /c start' || \
open_cmd='xdg-open' ;;
linux*) ! [[ $(uname -a) =~ "Microsoft" ]] && open_cmd='xdg-open' || {
open_cmd='cmd.exe /c start ""'
[[ -e "$1" ]] && { 1="$(wslpath -w "${1:a}")" || return 1 }
} ;;
msys*) open_cmd='start ""' ;;
*) echo "Platform $OSTYPE not supported"
return 1
Expand Down

0 comments on commit 0c1dfb4

Please sign in to comment.