Created
September 7, 2019 10:04
-
-
Save MWarCZ/ea51b1bbf91b73111ea6ac63943c8cdd to your computer and use it in GitHub Desktop.
Script for WLS on Windows 10. Useful script for opening file from bash with windows explorer.
This file contains hidden or 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
#! /usr/bin/env bash | |
# Nastaveni barev, pokud jde vystup na terminal. | |
# Set colors if output is terminal. | |
if [ -t 1 ] ; then | |
cl_ok="\e[1;32m" | |
cl_ko="\e[1;31m" | |
cl_h1="\e[1;36m" | |
cl_cl="\e[0m" | |
fi | |
if [ "$#" -eq 1 ]; then | |
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then | |
echo -e "\n ${cl_h1}HELP:${cl_cl}"; | |
echo -e " $0 relative/path/to/file/or/dir\n"; | |
echo -e " - Nefunguje pokud se nachazite mimo /mnt/"; | |
exit 0; | |
fi | |
winPrefix="" | |
absPath1="$(echo "$1" | cut -d '/' -f1)" | |
absPath2="$(echo "$1" | cut -d '/' -f2)" | |
absPath3="$(echo "$1" | cut -d '/' -f3)" | |
if [ "$absPath1" = "" ] && [ "$absPath2" = "mnt" ] && [[ "$absPath3" = [a-z] || "$absPath3" = [A-Z] ]] ; then | |
echo "OKX${absPath1}X${absPath2}X${absPath3}X" | |
winPrefix="${absPath3}:\\" | |
fi | |
# Absolutni cesta /mnt/<jednotka>/<cesta> | |
winPath="$(echo "$1" | sed 's|^/mnt/.\+/||g')" | |
# Vyreseni lomitek | |
winPath="$(echo "$winPath" | sed 's?/?\\?g')"; | |
winPath="${winPrefix}${winPath}" | |
echo -e "\n${cl_ok}OPEN:${cl_cl} \c"; | |
echo "'$winPath'"; | |
echo ""; | |
explorer.exe "$winPath"; | |
exit 0; | |
else | |
echo -e "\n${cl_ko}ERROR:${cl_cl} Je očekavan jen jeden argument.\n"; | |
exit 1; | |
fi; | |
# %LOCALAPPDATA%\lxss = / | |
# %LOCALAPPDATA%\lxss\home = /home | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment