Created
January 24, 2020 18:48
-
-
Save INDIAN2020/bfd9832f8fb02d1e9a5c4e07caa6af4f to your computer and use it in GitHub Desktop.
starting cygwin from a specific folder, the path can be passed from windows, for example as a context-menu for folders. (you place "cygwin.bat" in your cygwin folder, replacing the old one, and run the reg file to add a context menu for each folder)
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
@echo off | |
:: set code-page for UTF-8 charset. | |
chcp 65001 | |
:: normalise to fully qualified path. short path (8.3) is used for testing the path. | |
set FOLDER=%~s1 | |
for /f %%a in ("%FOLDER%") do ( set "FOLDER=%%~fsa" ) | |
:: verify existing folder. | |
if ["%FOLDER%"]==[""] ( goto RUN_STANDARD ) | |
if not exist %FOLDER% ( goto RUN_STANDARD ) | |
if not exist %FOLDER%\NUL ( goto RUN_STANDARD ) | |
goto RUN_FOLDER | |
::-------------------------------------------------------- | |
:RUN_FOLDER | |
:: prefer long-path. | |
set FOLDER=%~1 | |
echo. | |
echo Starting Cygwin From ^[%FOLDER%^] ... | |
:: convert to cygwin-compatible path (forward-slash, removing drive's ":" and /cygdrive/ as root) | |
set FOLDER=%FOLDER:\=/% | |
set FOLDER=%FOLDER::/=/% | |
set FOLDER=/cygdrive/%FOLDER% | |
call "%~dp0bin\mintty.exe" "-i" "/Cygwin-Terminal.ico" %~dp0bin\bash.exe -l -c "cd \"%FOLDER%\"; exec bash" - 2>nul >nul | |
goto EXIT | |
:RUN_STANDARD | |
echo. | |
echo Starting Cygwin From Home... | |
call "%~dp0bin\mintty.exe" "-i" "/Cygwin-Terminal.ico" "-" 2>nul >nul | |
goto EXIT | |
:EXIT | |
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
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\Directory\shell\open_in_cygwin] | |
@="Open In Cy&gwin" | |
[HKEY_CLASSES_ROOT\Directory\shell\open_in_cygwin\command] | |
@="\"C:\\cygwin\\Cygwin.bat\" \"%1\"" |
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
Windows Registry Editor Version 5.00 | |
[-HKEY_CLASSES_ROOT\Directory\shell\open_in_cygwin] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment