-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOpenWithSublime.bat
69 lines (63 loc) · 3.08 KB
/
OpenWithSublime.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
@echo off
:: Path to Sublime Text installation dir.
SET "stPath=%~dp0sublime_text.exe"
SET "stPathOnly=%~dp0"
:: Key name for the registry entries.
SET "UserEntry=Sublime Text"
SET "AdminEntry=Sublime Text As Admin"
:: Context menu texts.
SET "UserMenuText=Open with Sublime(&-)"
SET "AdminMenuText=Open with Sublime As Admin(&+)"
SET GIST_WORKSPACE=https://raw.githubusercontent.com/jcppkkk/OpenWithSublime/master
SET F_ELEVATE_CMD=OpenWithSublime_elevate.cmd
SET F_ELEVATE_VBS=OpenWithSublime_elevate.vbs
SET F_UNINSTALL=OpenWithSublime_uninstall.bat
call :download %GIST_WORKSPACE%/%F_ELEVATE_CMD% %F_ELEVATE_CMD%
call :download %GIST_WORKSPACE%/%F_ELEVATE_VBS% %F_ELEVATE_VBS%
call :download %GIST_WORKSPACE%/%F_UNINSTALL% %F_UNINSTALL%
call :check_Permissions
echo ===================================
echo Add context menu entry for all file types
SET REG_BASE=HKEY_CLASSES_ROOT\*\shell\%UserEntry%
reg add "%REG_BASE%" /t REG_SZ /v "" /d "%UserMenuText%" /f
reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%stPath%\" \"%%1\"" /f
echo Add context menu entry for all file types, open as admin
SET REG_BASE=HKEY_CLASSES_ROOT\*\shell\%AdminEntry%
reg add "%REG_BASE%" /t REG_SZ /v "" /d "%AdminMenuText%" /f
reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%stPathOnly%%F_ELEVATE_CMD%\" \"%stPath%\" \"%%1\"" /f
echo ===================================
echo Add context menu entry for folders
SET REG_BASE=HKEY_CLASSES_ROOT\Directory\shell\%UserEntry%
reg add "%REG_BASE%" /t REG_SZ /v "" /d "%UserMenuText%" /f
reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%stPath%\" \"%%1\"" /f
echo Add context menu entry for directories background
SET REG_BASE=HKEY_CLASSES_ROOT\Directory\Background\shell\%UserEntry%
@reg add "%REG_BASE%" /t REG_SZ /v "" /d "%UserMenuText%" /f
@reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
@reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%stPath%\" \"%%V\"" /f
echo ===================================
echo All done! press any key to leave.
echo ===================================
pause
goto :EOF
:check_Permissions
echo # Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Administrative permissions confirmed.
goto :EOF
) else (
echo Failure: Current permissions inadequate. Try to get elevation...
SET openwithsublime_elevation=1
call "%F_ELEVATE_CMD%" "%~fs0"
exit
)
:download
if not exist "%CD%\%2" (
C:\Windows\System32\WindowsPowerShell\v1.0\powershell "$wc = New-Object System.Net.WebClient;$wc.DownloadFile(\"%1\", \"%2\")"
echo Download %2
)
goto :EOF