Skip to content

Instantly share code, notes, and snippets.

@stefansundin stefansundin/sh.sh
Last active May 8, 2018

Embed
What would you like to do?
Bash on Windows shell script file association
#!/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..."
@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
@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
You can’t perform that action at this time.