Created
April 27, 2013 06:02
-
-
Save hao-ji-xing/5472052 to your computer and use it in GitHub Desktop.
sublime text 2 配置小助手
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 | |
title sublime text 2 配置小助手 | |
::st2主程序名称 | |
set sublime_exe=sublime_text.exe | |
::st2主程序全路径 | |
set exepath=%~dp0%sublime_exe% | |
::这是把\修改成\\,不然wsf里成了js的转义 | |
set exepath=%exepath:\=\\% | |
::右键菜单的字儿 | |
set context_menu_text=Edit with sublime | |
::editfile协议指向的脚本名 | |
set call_sublime_script=call_sublime.wsf | |
::editfile协议名 | |
set protocol_name=editfile | |
::检查当前文件夹是否拥有sublime_text.exe文件,以此判断是否处在st安装目录 | |
if exist %sublime_exe% ( | |
goto menu | |
) else ( | |
echo 请将此文件放在sublime text 2安装目录中执行. | |
pause | |
exit | |
) | |
:menu | |
cls | |
color 0a | |
echo **************************************************** | |
echo. | |
echo sublime text 2 配置小助手 | |
echo Authors:walter zhang Email:[email protected] | |
echo 兼容性还木有测试.反正win7下好使...帮助可以看注释 | |
echo. | |
echo **************************************************** | |
echo. | |
echo a.添加(Edit with sublime)右键菜单 | |
echo b.取消右键菜单 | |
echo c.将文本文件关联到sublime text2(.php .js .css) | |
echo d.取消文件关联 | |
echo e.注册editfile伪协议 | |
echo f.取消editfile伪协议 | |
echo 0.退出 | |
echo. | |
set choice= | |
set /p choice=请输入命令,按下Enter键执行: | |
if /I "%choice%"=="a" goto reg_context_menu | |
if /I "%choice%"=="b" goto del_context_menu | |
if /I "%choice%"=="c" goto reg_filetype_conn | |
if /I "%choice%"=="d" goto del_filetype_conn | |
if /I "%choice%"=="e" goto reg_editfile_protocol | |
if /I "%choice%"=="f" goto del_editfile_protocol | |
if /I "%choice%"=="h" goto helper | |
if /I "%choice%"=="0" goto exit | |
goto menu | |
::增加一个右键菜单 Edit with sublime, 使用sublime打开文件 | |
:reg_context_menu | |
reg add "HKEY_CLASSES_ROOT\*\shell\%context_menu_text%\Command" /t REG_SZ /d "\"%~dp0sublime_text.exe\" \"%%1\"" /f | |
pause | |
goto menu | |
:del_context_menu | |
reg delete "HKEY_CLASSES_ROOT\*\shell\%context_menu_text%" /f | |
pause | |
goto menu | |
::将.php,.js,.css文件关联到sublime,因为其他的扩展名试了有些无效,所以现在只支持仨个.. | |
:reg_filetype_conn | |
assoc .php=sublime_auto_file | |
assoc .js=sublime_auto_file | |
assoc .css=sublime_auto_file | |
ftype sublime_auto_file=%~dp0sublime_text.exe "%%1" | |
echo 操作完成 | |
pause | |
goto menu | |
:del_filetype_conn | |
assoc .php= 1>nul 2>nul | |
assoc .js=JSFile 1>nul 2>nul | |
assoc .css= 1>nul 2>nul | |
echo 操作完成 | |
pause | |
goto menu | |
::注册editfile伪协议后可以使用 "editfile:文件路径:行数:列数" 的html链接 | |
::方式使用sublime打开指定路径的文件并且跳转到相应行列,例如 | |
::<a href="editfile:F:/svn/code.php">打开code.php</a> | |
::<a href="editfile:F:/svn/code.php:10">打开code.php,并且定位第十行</a> | |
::<a href="editfile:F:/svn/code.php:10:5">打开code.php,并且定位第十行第五列</a> | |
:reg_editfile_protocol | |
reg add "HKEY_CLASSES_ROOT\%protocol_name%" /v "URL Protocol" /t REG_SZ /d "" /f | |
reg add "HKEY_CLASSES_ROOT\%protocol_name%\shell\open\command" /t REG_SZ /d "wscript \"%~dp0%call_sublime_script%\" \"%%1\"" /f | |
::写入一个wsf文件,用来处理协议传递的参数,并且调用st2主程序打开 | |
::因为js和vbs的默认关联都可能被改掉从而导致wscript调用失败,所以使用.wsf文件,这个比较安全 | |
echo ^<Job^>^<script language^="JScript"^>>%call_sublime_script% | |
echo new ActiveXObject('wscript.shell').run("%exepath% "+>>%call_sublime_script% | |
echo WScript.Arguments(0).replace(/^^%protocol_name%:(?:\/\/)?/,''));>>%call_sublime_script% | |
echo ^</script^>^</Job^>>>%call_sublime_script% | |
pause | |
goto menu | |
:del_editfile_protocol | |
reg delete "HKEY_CLASSES_ROOT\%protocol_name%" /f | |
if exist %call_sublime_script% (del /q %call_sublime_script% ) | |
pause | |
goto menu | |
:exit | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment