Last active
July 5, 2017 07:55
-
-
Save patroza/4b0593c75ed88d9018008ecca0ceb6e5 to your computer and use it in GitHub Desktop.
Running windows commands with .envrc (dynamically converting exports) from WSL (Bash on Windows)
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
#!/bin/bash | |
command=`basename "$0"` | |
run-windows-command "$command" "$@" |
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
#!/bin/bash | |
command=`basename "$0"` | |
run-windows-command "$command" "$@" |
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
#!/bin/bash | |
command="$1" | |
commands="chcp 437" | |
found="" | |
windowsfound="" | |
upsearch () { | |
slashes=${PWD//[^\/]/} | |
directory="$PWD" | |
windowsdirectory=directory | |
for (( n=${#slashes}; n>0; --n )) | |
do | |
test -e "$directory/.envrc" && windowsfound="$windowsdirectory" && found="$directory" && return | |
windowsdirectory="..\\" | |
directory="$directory/.." | |
done | |
} | |
upsearch | |
if [ "$found" = "$PWD" ]; then | |
found="." | |
windowsfound="." | |
fi | |
if [ "$found" ]; then | |
sed -e 's/export/set/g' $found/.envrc | sed 's/#/REM/g' | sed "s/'//g" > "$found/.env.bat" | |
commands+=" && $windowsfound\.env.bat" | |
fi | |
commands+=" && " | |
commands+=$command | |
commands+=" ${@:2}" | |
echo $commands | |
/mnt/c/Windows/System32/cmd.exe /c $commands |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment