-
-
Save fcenobi/1afecf0f0cbd69faf2b41c34f4047a3a to your computer and use it in GitHub Desktop.
export win's environment variable to WSL environment variable
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
conv_brackets_uscore() { | |
echo $1 | sed -E 's/[][{}()]/_/g' | |
return 0 | |
} | |
conv_path_win_linux() { | |
local _path | |
local _del_trailing_slash_path | |
_path="$(echo $1| \ | |
tr '\\' '/' | \ | |
sed -E "s/^(.):/\/mnt\/\l\1/" | \ | |
tr -d '\r' | \ | |
sed -e 's/WINDOWS/Windows/')" | |
_del_trailing_slash_path="${_path%/}" | |
echo "${_del_trailing_slash_path}" | |
return 0 | |
} | |
export_win_env_var() { | |
cmd.exe /c set | \ | |
grep -v 'WSLENV' | \ | |
grep -iv '^path' | \ | |
grep -v \; | \ | |
tr '\\U' '/U' | \ | |
while read -r win_env_var_list; do | |
win_env_var="${win_env_var_list%%=*}" | |
win_env_var_val="${win_env_var_list#*=}" | |
converted_win_env_var="$(conv_brackets_uscore ${win_env_var})" | |
converted_win_env_var_val="$(conv_path_win_linux "${win_env_var_val}")" | |
export "WIN_${converted_win_env_var}"="${converted_win_env_var_val}" | |
done; | |
return 0 | |
} | |
export_win_env_var |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment