Skip to content

Instantly share code, notes, and snippets.

@macchaberrycream
Last active August 21, 2020 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save macchaberrycream/caee61325551bda797500a0cf8db6df4 to your computer and use it in GitHub Desktop.
Save macchaberrycream/caee61325551bda797500a0cf8db6df4 to your computer and use it in GitHub Desktop.
export win's environment variable to WSL environment variable
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