簡單的個人幫助系統(tǒng)
編程的時候,需要參考許多的幫助,一個有良好組織習(xí)慣的人,一般會把需要用到的幫助都放到同一個文件夾里邊,當(dāng)要用到的時候,直接到文件夾中打開相應(yīng)的幫助就可以了。但是bigtall的做法和大家可能有點(diǎn)不一樣,因為我是一個懶惰的人,所以經(jīng)常忘記把文檔整理起來,而且不喜歡做什么事情都把一個資源管理器窗口打開著,我經(jīng)常打開的窗口是cmd窗口,所以我編制了我自己的幫助系統(tǒng):一個簡單的批處理文件myhelp.bat。
我的幫助系統(tǒng)有如下的優(yōu)點(diǎn):
- 使用簡單,只需要簡單輸入命令就可以打開相應(yīng)的幫助文件。比如打開樣式表CSS2的幫助
D:\WORK>myhelp css2 - 維護(hù)方便,需要增加新的幫助內(nèi)容,我們只需要使用一個簡單的名字和幫助文檔關(guān)聯(lián)起來,比如增加c#的幫助文檔:
D:\WORK>myhelp /a csharp "%ProgramFiles%\Microsoft Visual Studio 9.0\VC#\Specifications\2052\CSharp Language Specification.doc"
如果您覺得每次打開word不方便,那就可以用/o參數(shù)指定一個應(yīng)用程序,應(yīng)用程序可以用簡寫代替,內(nèi)置"ie"代表Internet Explorer - 可以隨時知道你有多少內(nèi)置幫助存在,使用/l參數(shù)
- 修改方便,使用參數(shù)/e直接打開幫助批處理代碼進(jìn)行修改
- 你如果想學(xué)習(xí)批處理的編寫,我的代碼就是很好的參考,它包含了幾乎所有的常用法,也包含了一定的高級用法。
代碼如下,請復(fù)制下來粘貼到文件中,記得文件要放在你的path查找范圍內(nèi)哦!
@echo off
rem ============================================================================
rem 可擴(kuò)展的幫助系統(tǒng)
rem 記得修改 HELPDIR 參數(shù)的值
rem ============================================================================
rem 打開cmd擴(kuò)展
set TSTEXT=a
if not #!TSTEXT!#==#a# (
set TSTEXT=
cmd.exe /V:ON /C %0 %*
exit /b
)
set TSTEXT=
rem ===================================
rem 請修改HELPDIR為你自己的存放位置
set HELPDIR=d:\tools\help
rem ===================================
rem 清除殘余的環(huán)境變量
rem 保存當(dāng)前工作目錄
set CWD=%CD%
rem 如果第一個參數(shù)是DEBUG,表明打開調(diào)試選項
rem 需要設(shè)DEBUG變量,剩余命令行放在CMDLINE變量中
set DEBUG=
set CMDLINE=
set THIS=%~f0
set THISNAME=%~nx0
set THISDIR=%~dp0
rem 生成隨機(jī)數(shù)字
set RND=%TIME::=.%-%RANDOM%
rem 生成8位日期數(shù)字
set YYYYMMDD=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
rem 生成精確到百分秒的8位時間數(shù)字
set HHMMSSTT=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%%TIME:~9,2%
rem 處理DEBUG參數(shù),用于調(diào)試輔助
set CMDLINE0=%*
if #%1# == #DEBUG# set DEBUG=on
if #%1# == #debug# set DEBUG=on
if #%DEBUG%# == #on# set CMDLINE=%CMDLINE0:~5%
if NOT #%DEBUG%# == #on# set CMDLINE=%CMDLINE0%
set CMDLINE0=
if #%DEBUG%# == #on# shift
@if #%DEBUG%# == #on# @echo on
rem 此處需要修改默認(rèn)無參數(shù)的行為
if #%1# == ## goto help
rem 檢查是否help顯示
if #%1# == #/?# goto help
if #%1# == #-?# goto help
if #%1# == #?# goto help
for %%a in (help HELP /help /HELP -help -HELP --help --HELP h H /h /H -h -H --h --H ) do if #%1# == #%%a# goto help
set MAINACTION=
rem ----------------- 用戶代碼開始 -----------------
set O_KEY=
set O_SRC=
set O_PROG=
rem 處理參數(shù)循環(huán)開始
:opt_an
set __TEMP_O_=%1
set NEXT_OPTION_PREFIX=%__TEMP_O_:~0,1%
set NEXT_IS_OPTION=
if not "%NEXT_OPTION_PREFIX%" == "/" if not "%NEXT_OPTION_PREFIX%" == "-" set NEXT_IS_OPTION=y
set __TEMP_O_=
rem 無后隨參數(shù)
for %%a in ( /e -e /E -E ) do if #%1# == #%%a# start notepad "%THIS%" && goto opt_exit
rem 帶后隨數(shù)據(jù)的參數(shù)
for %%a in ( /a -a /A -A ) do if #%1# == #%%a# goto opt_A
for %%a in ( /o -o /O -O ) do if #%1# == #%%a# goto opt_O
rem 這里處理可中斷的無后隨參數(shù)
for %%a in ( /l -l /L -L ) do if #%1# == #%%a# set MAINACTION=list&& goto opt_exit
rem 這里處理可中斷的有后隨參數(shù)
rem 這里處理非option參數(shù)
if "%MAINACTION%" == "" set MAINACTION=provide
goto opt_exit
rem ----------------- 用戶代碼結(jié)束 -----------------
rem 處理無中斷參數(shù)
goto opt_nx
:opt_A
set MAINACTION=add
shift
if #%1# == ## goto help
if #%2# == ## goto help
set O_KEY=%1
shift
set O_SRC=%1
goto opt_nx
rem 處理可中斷參數(shù)
:opt_O
shift
if #%1# == ## goto help
set O_PROG=%1
goto opt_exit
rem 循環(huán)的判斷
:opt_nx
shift
if not #%1# == ## goto opt_an
:opt_exit
set NEXT_OPTION_PREFIX=
rem 處理參數(shù)循環(huán)結(jié)束
if #%MAINACTION%# == ## goto help
goto start
:help
echo -----======================================================================-----
echo usage: %THISNAME% [/a key src] [/o prog] helpkey1 helpkey2
echo /a key src 添加一個新的幫助
echo /o program 打開幫助文件的可執(zhí)行文件
echo /e 自動打開編輯%THISNAME%
echo /l 列舉當(dāng)前所有可以提供的幫助名稱
echo helpkey 幫助名稱
goto end
:start
rem ----------------- 用戶代碼開始 -----------------
if "%MAINACTION%" == "" goto help
goto do_%MAINACTION%
goto fin
rem 用戶正式處理代碼,所有的功能標(biāo)簽直接用do_開頭
:do_provide
set FNDKEY=
for /f "tokens=1 skip=180 delims= " %%i in ('type "%THIS%"') do (
if "%FNDKEY%" == "" if /i "%%i" == ":sub_%1" set FNDKEY=y
)
if "%FNDKEY%" == "" echo help for [%1] not found! & goto l_prv_exit
call:sub_%1
:l_prv_exit
set FNDKEY=
shift
if not "%1" == "" goto :do_provide
goto fin
:do_add
set FNDKEY=
for /f "tokens=1 skip=180 delims= " %%i in ('type "%THIS%"') do (
if "%FNDKEY%" == "" if /i "%%i" == ":sub_%O_KEY%" set FNDKEY=y
)
if not "%FNDKEY%" == "" echo "help key %O_KEY% already exists, please use /e to edit!" & goto l_add_exit
if '%O_PROG%' == 'ie' set O_PROG=%ProgramFiles%\Internet Explorer\iexplore.exe
if "%O_PROG%" == "" set O_PROG=start "help %O_KEY%"
echo :sub_%O_KEY% >> "%THIS%"
echo %O_PROG% %O_SRC% >> "%THIS%"
echo goto :EOF >> "%THIS%"
echo help %O_KEY% append OK!
:l_add_exit
set FNDKEY=
goto fin
:do_list
for /f "tokens=1 skip=180 delims= " %%i in ('type "%THIS%"') do (
set LIST_KEY=%%i
if /i "!LIST_KEY:~0,5!" == ":sub_" echo !LIST_KEY:~5!
)
goto fin
:fin
rem 用戶收尾代碼,所有start之后的代碼都跳轉(zhuǎn)到這里結(jié)束
rem ----------------- 用戶代碼結(jié)束 -----------------
goto end
:end
rem ----------------- 用戶代碼開始 -----------------
set O_KEY=
set O_SRC=
set O_PROG=
set HELPDIR=
rem ----------------- 用戶代碼結(jié)束 -----------------
set NEXT_IS_OPTION=
set NEXT_OPTION_PREFIX=
set MAINACTION=
set RND=
set YYYYMMDD=
set HHMMSSTT=
set THIS=
set THISNAME=
set THISDIR=
set CMDLINE=
set DEBUG=
set CWD=
goto :EOF
rem ------------幫助區(qū),所有的幫助key用sub_開頭,要更新幫助請編輯以下部分---------------
rem ============================================================================
rem 可擴(kuò)展的幫助系統(tǒng)
rem 記得修改 HELPDIR 參數(shù)的值
rem ============================================================================
rem 打開cmd擴(kuò)展
set TSTEXT=a
if not #!TSTEXT!#==#a# (
set TSTEXT=
cmd.exe /V:ON /C %0 %*
exit /b
)
set TSTEXT=
rem ===================================
rem 請修改HELPDIR為你自己的存放位置
set HELPDIR=d:\tools\help
rem ===================================
rem 清除殘余的環(huán)境變量
rem 保存當(dāng)前工作目錄
set CWD=%CD%
rem 如果第一個參數(shù)是DEBUG,表明打開調(diào)試選項
rem 需要設(shè)DEBUG變量,剩余命令行放在CMDLINE變量中
set DEBUG=
set CMDLINE=
set THIS=%~f0
set THISNAME=%~nx0
set THISDIR=%~dp0
rem 生成隨機(jī)數(shù)字
set RND=%TIME::=.%-%RANDOM%
rem 生成8位日期數(shù)字
set YYYYMMDD=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
rem 生成精確到百分秒的8位時間數(shù)字
set HHMMSSTT=%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%%TIME:~9,2%
rem 處理DEBUG參數(shù),用于調(diào)試輔助
set CMDLINE0=%*
if #%1# == #DEBUG# set DEBUG=on
if #%1# == #debug# set DEBUG=on
if #%DEBUG%# == #on# set CMDLINE=%CMDLINE0:~5%
if NOT #%DEBUG%# == #on# set CMDLINE=%CMDLINE0%
set CMDLINE0=
if #%DEBUG%# == #on# shift
@if #%DEBUG%# == #on# @echo on
rem 此處需要修改默認(rèn)無參數(shù)的行為
if #%1# == ## goto help
rem 檢查是否help顯示
if #%1# == #/?# goto help
if #%1# == #-?# goto help
if #%1# == #?# goto help
for %%a in (help HELP /help /HELP -help -HELP --help --HELP h H /h /H -h -H --h --H ) do if #%1# == #%%a# goto help
set MAINACTION=
rem ----------------- 用戶代碼開始 -----------------
set O_KEY=
set O_SRC=
set O_PROG=
rem 處理參數(shù)循環(huán)開始
:opt_an
set __TEMP_O_=%1
set NEXT_OPTION_PREFIX=%__TEMP_O_:~0,1%
set NEXT_IS_OPTION=
if not "%NEXT_OPTION_PREFIX%" == "/" if not "%NEXT_OPTION_PREFIX%" == "-" set NEXT_IS_OPTION=y
set __TEMP_O_=
rem 無后隨參數(shù)
for %%a in ( /e -e /E -E ) do if #%1# == #%%a# start notepad "%THIS%" && goto opt_exit
rem 帶后隨數(shù)據(jù)的參數(shù)
for %%a in ( /a -a /A -A ) do if #%1# == #%%a# goto opt_A
for %%a in ( /o -o /O -O ) do if #%1# == #%%a# goto opt_O
rem 這里處理可中斷的無后隨參數(shù)
for %%a in ( /l -l /L -L ) do if #%1# == #%%a# set MAINACTION=list&& goto opt_exit
rem 這里處理可中斷的有后隨參數(shù)
rem 這里處理非option參數(shù)
if "%MAINACTION%" == "" set MAINACTION=provide
goto opt_exit
rem ----------------- 用戶代碼結(jié)束 -----------------
rem 處理無中斷參數(shù)
goto opt_nx
:opt_A
set MAINACTION=add
shift
if #%1# == ## goto help
if #%2# == ## goto help
set O_KEY=%1
shift
set O_SRC=%1
goto opt_nx
rem 處理可中斷參數(shù)
:opt_O
shift
if #%1# == ## goto help
set O_PROG=%1
goto opt_exit
rem 循環(huán)的判斷
:opt_nx
shift
if not #%1# == ## goto opt_an
:opt_exit
set NEXT_OPTION_PREFIX=
rem 處理參數(shù)循環(huán)結(jié)束
if #%MAINACTION%# == ## goto help
goto start
:help
echo -----======================================================================-----
echo usage: %THISNAME% [/a key src] [/o prog] helpkey1 helpkey2

echo /a key src 添加一個新的幫助
echo /o program 打開幫助文件的可執(zhí)行文件
echo /e 自動打開編輯%THISNAME%
echo /l 列舉當(dāng)前所有可以提供的幫助名稱
echo helpkey 幫助名稱
goto end
:start
rem ----------------- 用戶代碼開始 -----------------
if "%MAINACTION%" == "" goto help
goto do_%MAINACTION%
goto fin
rem 用戶正式處理代碼,所有的功能標(biāo)簽直接用do_開頭
:do_provide
set FNDKEY=
for /f "tokens=1 skip=180 delims= " %%i in ('type "%THIS%"') do (
if "%FNDKEY%" == "" if /i "%%i" == ":sub_%1" set FNDKEY=y
)
if "%FNDKEY%" == "" echo help for [%1] not found! & goto l_prv_exit
call:sub_%1
:l_prv_exit
set FNDKEY=
shift
if not "%1" == "" goto :do_provide
goto fin
:do_add
set FNDKEY=
for /f "tokens=1 skip=180 delims= " %%i in ('type "%THIS%"') do (
if "%FNDKEY%" == "" if /i "%%i" == ":sub_%O_KEY%" set FNDKEY=y
)
if not "%FNDKEY%" == "" echo "help key %O_KEY% already exists, please use /e to edit!" & goto l_add_exit
if '%O_PROG%' == 'ie' set O_PROG=%ProgramFiles%\Internet Explorer\iexplore.exe
if "%O_PROG%" == "" set O_PROG=start "help %O_KEY%"
echo :sub_%O_KEY% >> "%THIS%"
echo %O_PROG% %O_SRC% >> "%THIS%"
echo goto :EOF >> "%THIS%"
echo help %O_KEY% append OK!
:l_add_exit
set FNDKEY=
goto fin
:do_list
for /f "tokens=1 skip=180 delims= " %%i in ('type "%THIS%"') do (
set LIST_KEY=%%i
if /i "!LIST_KEY:~0,5!" == ":sub_" echo !LIST_KEY:~5!
)
goto fin
:fin
rem 用戶收尾代碼,所有start之后的代碼都跳轉(zhuǎn)到這里結(jié)束
rem ----------------- 用戶代碼結(jié)束 -----------------
goto end
:end
rem ----------------- 用戶代碼開始 -----------------
set O_KEY=
set O_SRC=
set O_PROG=
set HELPDIR=
rem ----------------- 用戶代碼結(jié)束 -----------------
set NEXT_IS_OPTION=
set NEXT_OPTION_PREFIX=
set MAINACTION=
set RND=
set YYYYMMDD=
set HHMMSSTT=
set THIS=
set THISNAME=
set THISDIR=
set CMDLINE=
set DEBUG=
set CWD=
goto :EOF
rem ------------幫助區(qū),所有的幫助key用sub_開頭,要更新幫助請編輯以下部分---------------

公眾號:老翅寒暑
浙公網(wǎng)安備 33010602011771號