Skip to content

Commit

Permalink
Modified .bashrc to better handle Windows executables
Browse files Browse the repository at this point in the history
Added a command_not_found_handle() function which will
launch Windows executables from WSL even if the .exe
extension is omitted.

Code copied from microsoft/WSL#2003
  • Loading branch information
sdtrotter committed Jul 12, 2018
1 parent 8f2c9de commit d5c6891
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,23 @@ if ! shopt -oq posix; then
. /etc/bash_completion
fi
fi

# invoke windows executables and built-in commands by typing only
# the command name WITHOUT the .exe normally required
# based on discussion in https://github.com/Microsoft/WSL/issues/2003
command_not_found_handle() {
if cmd.exe /c "(where $1 || (help $1 |findstr /V Try)) >nul 2>nul && ($* || exit 0)"; then
return $?
else
if [ -x /usr/lib/command-not-found ]; then
/usr/lib/command-not-found -- "$1"
return $?
elif [ -x /usr/share/command-not-found/command-not-found ]; then
/usr/share/command-not-found/command-not-found -- "$1"
return $?
else
printf "%s: command not found\n" "$1" >&2
return 127
fi
fi
}

0 comments on commit d5c6891

Please sign in to comment.