Last active
November 25, 2019 15:52
-
-
Save esabook/10f0e36c0b5f09320c84a481d40353c6 to your computer and use it in GitHub Desktop.
Accessing all windows app executable (*.exe) from Windows Subsystem for Linux (WSL) without extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
how to use: | |
nano ~/.bashrc | |
paste block of command_not_found_handle() in bellow | |
save & test | |
example test: | |
notepad as notepad.exe | |
explorer as explorer.exe | |
```for bash | |
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 | |
} | |
``` | |
```for zsh | |
command_not_found_handler() | |
{ | |
cmd=$1 | |
shift | |
args=( "$@" ) | |
saveIFS="$IFS" | |
IFS=: | |
for dir in ${(@s/:/)PATH}; do | |
for executable in "$dir/$cmd.exe" "$dir/$cmd.com" "$dir/$cmd.bat"; do | |
if [ -x $executable ]; then | |
IFS="$saveIFS" | |
"$executable" "${args[@]}" | |
return | |
fi | |
done | |
done | |
IFS="$saveIFS" | |
if [ -x /usr/lib/command-not-found ]; then | |
/usr/lib/command-not-found -- "$cmd" "${args[@]}" | |
return $? | |
elif [ -x /usr/share/command-not-found/command-not-found ]; then | |
/usr/share/command-not-found/command-not-found -- "$1" "${args[@]}" | |
return $? | |
else | |
printf "%s: command not found\n" "$cmd" >&2 | |
return 127 | |
fi | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment