之前我写过一个python3的脚本可以实现alias的作用,后来想想毕竟Python不是所有人都会装,那个脚本的适用性也就受到了限制,
今天我用批处理脚本重写了一下那个alias的脚本,如下(共五个文件readini.bat,open.bat,gotopath.bat,commandlist.ini,help.txt):
你可以将脚本放到一个文件夹中,在桌面上建立open.bat的快捷方式,
邮件单击快捷方式,选择属性,为快捷方式添加快捷键:Ctrl+Alt+R
这样无论在什么窗口下,同时按住Ctrl+Alt+R,open.bat就会执行。
readini.bat内容如下:
rem @echo off & setlocal enabledelayedexpansion
rem echo 参数个数: %0 %1 %2 %3
set name1145264=
set namelist1145264=
set param1145264=
set paramlist1145264=
FOR /F "eol=; tokens=1* usebackq delims==" %%i IN (%1) do (
rem echo %%i %%j
set p=%%i
rem echo p=!p!
rem echo 取字符!p! !p:~0,1! !p:~-1! !p:~1,-1!
if "!p:~0,1!"=="[" (
if "!p:~-1!"=="]" (
rem @echo 条件!p:~1,-1!
set name1145264=!p:~1,-1!
set namelist1145264=!namelist1145264!,!name1145264!
)
)
rem echo name1145264=!name1145264! namelist1145264=!namelist1145264! paramlist1145264=!paramlist1145264! 输入 %2
if "[!name1145264!]" NEQ "%%i" (
if "!name1145264!"=="%2" (
set paramlist1145264=!paramlist1145264!,%%i
if "%3"=="%%i" (
set param1145264=%%j
)
)
)
)
rem echo ------------------------
rem echo name1145264=!name1145264!
set return=
if "%2" EQU "" (
rem 名称列表
rem echo "!namelist1145264:~1!"
set return=!namelist1145264:~1!
if "!namelist1145264!" NEQ "" (
set return=!namelist1145264:~1!
) else (
set return=
)
) else (
if "%3" EQU "" (
rem 属性列表
rem echo "!paramlist1145264!"
if "!paramlist1145264!" NEQ "" (
set return=!paramlist1145264:~1!
)else (
set return=
)
) else (
rem 属性值
rem echo "!param1145264!"
set return=!param1145264!
if "!param1145264!" NEQ "" (
set return=!param1145264!
)else (
set return=
)
)
)
set name1145264=
set namelist1145264=
set param1145264=
set paramlist1145264=
set p=
rem @echo on
open.bat内容如下:
@echo off & setlocal enabledelayedexpansion
set filename=commandlist.ini
set myname=0
:loop1
set myname=
set /P myname=请输入简写:
rem echo 您输入的是%myname%
if "%myname%"=="" (
rem echo "输入为空,请重新输入"
goto :loop1
) else (
if "%myname%"=="help" (
type help.txt
echo .
goto :loop1
)
if "%myname%"=="quit" (
exit 1
)
if "%myname%"=="show" (
call readini %filename%
set p=!return!
for %%i in (!p!) do (
call readini %filename% %%i note
set p2=%%i
echo !p2:~0,15! !return!
)
goto :loop1
)
if "%myname%"=="edit" (
notepad %filename%
goto :loop1
)
if "!myname:~0,2!"=="g " (
rem echo call !myname:~0,2! %filename% !myname:~2!
call gotopath %filename% !myname:~2!
if !return! EQU 0 (
goto loop1
) else (
exit
rem echo =================exit===================
)
echo 程序不可能到运行这里的
goto :loop1
)
call readini %filename% %myname% command
set mycmd=!return!
call readini commandlist.ini %myname% param
set myparam=!return!
call readini commandlist.ini %myname% path
set mypath=!return!
call readini commandlist.ini %myname% note
set mynote=!return!
if "!mycmd!"=="" (
echo 没有找到%myname%对应的命令
set myname=
goto :loop1
) else (
echo 程序说明:!mynote!
set errorlevel=
rem echo 输出%errorlevel%
if "!mypath!" NEQ "" (
rem echo start "!mycmd!" /D!mypath! !mycmd! !myparam!
start "!mycmd!" /D!mypath! !mycmd! !myparam!
) else (
start "!mycmd!" !mycmd! !myparam!
)
if %errorlevel% NEQ 0 (
@echo 错误代码:%errorlevel%
goto :loop1
set myname=
set errorlevel=0
)
rem @echo 运行成功
exit
)
)
@echo on
pause
gotopath.bat 内容如下:
rem @echo off & setlocal enabledelayedexpansion
rem setlocal ENABLEDELAYEDEXPANSION
rem gp: goto path 去简称程序的目录下
rem echo call readini %1 %2 path
set return=
call readini %1 %2 path
if "!return!" NEQ "" (
start "gotopath" explorer !return!
set return=1
) else (
echo 没有找到%2.path属性
set return=0
)
rem echo 执eee行结果:!return!
rem @echo on
help.txt内容如下:
-----------------------------------------
帮助文档
edit 编辑配置文件
help 显示帮助文档
quit 退出系统
show 显示简写命令列表
g 去简称命令的path下,例如:g ues去UE的path
其他 执行简写命令
-----------------------------------------
commandlist.ini内容如下:
;测试用ini文件
;注意 名称中不能有等号和空格
; 属性和等号之间不能有空格
[cmd]
command=cmd.exe
param=
path="E:\Users\changliang02\Documents"
note=命令窗口
[np]
command=notepad
param=
path=
note=记事本
[dl]
command=explorer.exe
param="E:\Users\changliang02\Downloads"
path=
note=下载目录
[xls]
command=EXCEL.EXE
param=
path="C:\Program Files\Microsoft Office\Office15"
note=Excelb办公软件
[sr]
command=SecureCRT.exe
param=
path="D:\Tools\securecrt"
note=SecureCRT远程Telnet工具
[et]
command=Everything.exe
param=
path="D:\Tools\Everything"
note=查找本地文件
[ues]
command=UEStudio.exe
param=
path="D:\Program Files\IDM Computer Solutions\UEStudio"
note=UEStudio超级文本编辑器
希望对大家的学习和工作有帮助。
脚本编程,简单,绿色,无毒,快乐。