Last active
September 6, 2024 03:09
-
-
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
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 | |
# Felix E. Klee <[email protected]> | |
MSLINK=mslink_v1.3.sh | |
SYNCTHING_DIR="/mnt/c/Users/Felix/Syncthing" | |
SYNCTHING_WIN_DIR='C:\Users\Felix\Syncthing' | |
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" == "$SYNCTHING_DIR"* ]]; then | |
DIR="$SYNCTHING_DIR" | |
WIN_DIR="$SYNCTHING_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