Last active
February 2, 2021 09:27
-
-
Save stefansundin/83933f6e71bc81aa66e6d2bf0a5602a3 to your computer and use it in GitHub Desktop.
Bash on Windows shell script file association
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
#!/bin/bash | |
# Put this file in C:\ and then run z-register.bat by right clicking it and using "Run as Administrator" | |
# Translate the windows path to the equivalent Bash on Windows path, then run it! | |
drive="${1:0:1}" | |
path="${1:2}" | |
dir=$(dirname "/mnt/${drive,,}${path//\\/\/}") | |
cd "$dir" | |
"/mnt/${drive,,}${path//\\/\/}" | |
echo | |
read -p "Press enter key to close window..." |
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
@echo off | |
@echo. | |
echo If you see "ERROR: Access is denied." then you need to right click and use "Run as Administrator". | |
@echo. | |
echo Removing .sh association... | |
reg delete HKCR\.sh /f | |
reg delete HKCR\sh_sh /f | |
@echo. | |
pause |
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
@echo off | |
@echo. | |
if not exist "C:\sh.sh" ( | |
echo Warning: Can't find C:\sh.sh | |
echo Please move sh.sh there. | |
@echo. | |
pause | |
exit /b | |
) | |
echo If you see "ERROR: Access is denied." then you need to right click and use "Run as Administrator". | |
@echo. | |
echo Associating .sh | |
reg add HKCR\.sh /ve /t REG_SZ /d "sh_sh" /f | |
reg add HKCR\sh_sh /ve /t REG_SZ /d "Shell Script" /f | |
reg add HKCR\sh_sh\DefaultIcon /ve /t REG_SZ /d "%%USERPROFILE%%\AppData\Local\lxss\bash.ico,0" /f | |
reg add HKCR\sh_sh\shell\open\command /ve /t REG_SZ /d "\"%SystemRoot%\System32\bash.exe\" --login -c \"/mnt/c/sh.sh '%%1'\"" /f | |
@echo. | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment