Skip to content

Instantly share code, notes, and snippets.

@patroza
Last active July 5, 2017 07:55
Show Gist options
  • Save patroza/4b0593c75ed88d9018008ecca0ceb6e5 to your computer and use it in GitHub Desktop.
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)
#!/bin/bash
command=`basename "$0"`
run-windows-command "$command" "$@"
#!/bin/bash
command=`basename "$0"`
run-windows-command "$command" "$@"
#!/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