Skip to content

Instantly share code, notes, and snippets.

@feklee
Last active November 23, 2023 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feklee/678c630aa7f84ceda1c766333b37e7d3 to your computer and use it in GitHub Desktop.
Save feklee/678c630aa7f84ceda1c766333b37e7d3 to your computer and use it in GitHub Desktop.
Prints the path in Windows of a path in my Linux virtual machine
#!/bin/bash
# Felix E. Klee <felix.klee@inka.de>
MSLINK=mslink_v1.3.sh
DROPBOX_DIR="/mnt/c/Users/Felix/Dropbox"
DROPBOX_WIN_DIR='C:\Users\Felix\Dropbox'
HOME_DIR="/home/felix"
HOME_WIN_DIR='\\wsl.localhost\Ubuntu\home\felix'
show_help() {
cat << EOF
Usage: ${0##*/} PATH
Prints the path in Windows of PATH in my Linux virtual machine.
EOF
}
if [ "$#" -ne 1 ]; then
show_help >&2
exit 1
fi
FULLPATH="$(realpath "$1")"
if [[ "$FULLPATH" == "$DROPBOX_DIR"* ]]; then
DIR="$DROPBOX_DIR"
WIN_DIR="$DROPBOX_WIN_DIR"
elif [[ "$FULLPATH" == "$HOME_DIR"* ]]; then
DIR="$HOME_DIR"
WIN_DIR="$HOME_WIN_DIR"
else
echo "Path not supported" >&2
exit 1
fi
RELPATH="$(realpath --relative-to="$DIR" "$FULLPATH")"
WINPATH="$WIN_DIR"'\'"${RELPATH////\\}"
echo "$WINPATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment