Win10 自用 Bat 脚本小工具
@
1. 背景
主要是两个点吧:
-
其一是一些常用的命令啊或者什么的,有时候在命令行记不住
-
然后是一些命令太长了,每次都打太麻烦。
啊,对了,记得把Bat脚本文件所在的文件夹加入到环境变量当中,这样就可以把他们当作全局命令来随处调用,具体操作就不赘述了。
2. 过程
2.1. 提示
这个类别主要是,根据输入的参数,在命令行输出指定的文件里面的内容,也就是相应的类似于帮助文档一类的东西。
教程一类的,首先是整体的结构,肯定是一个选择分支,参考这个[1]
于是我们得到了:
@echo off
echo.
:: echo a blank line
if "%1" == "scrcpy" (
goto scrcpy
)
if "%1" == "powershell" (
goto powshell
)
if "%1" == "sublime" (
goto sublime
)
goto error
:scrcpy
type D:\Software\Script\ScrcpyShotcuts.txt
goto end
:powshell
type D:\Software\Script\PowerShell.txt
goto end
:sublime
type D:\Software\Script\Sublime.txt
goto end
:error
echo Invalid choice !
goto end
:end
echo.
echo.
贴几个文件吧:
首先是这个,删除PowerShell的历史记录
This is the command of powshell
Remove-Item (Get-PSReadlineOption).HistorySavePath
然后是,删除Sublime的历史记录,记得改成自己的路径:
This is the command of sublime text
Get-ChildItem "C:\Users\UserName\AppData\Roaming\Sublime Text\Local\"
Remove-Item "C:\Users\UserName\AppData\Roaming\Sublime Text\Local\Session.sublime_session"
Remove-Item "C:\Users\UserName\AppData\Roaming\Sublime Text\Local\*"
2.2. 运行
这一块主要就是,简化复杂命令
用到的教程有:
上面的删除是PowerShell的,这里我们需要一个CMD版本,参考这个[4]
以及一个读取Yes/No的分支选择,参考这个[6]和这个[7]
不过这里面似乎不太建议使用echo.,我之前也是在其他地方找到的这个写法,懒得改了
于是我们得到了:
@echo off
echo.
:: echo a blank line
if "%1" == "scrcpy" (
goto scrcpy
)
if "%1" == "daily" (
goto daily
)
rem if "%1" == "scrcpy_software" (
rem goto scrcpy_software
rem )
goto error
rem :scrcpy_software
rem call D:\Software\scrcpy-win64-v2.1.1\LaunchScrcpyNoConsole.exe
rem echo Finish call LaunchScrcpyNoConsole.exe !
rem goto end
:scrcpy
scrcpy --shortcut-mod=lctrl --always-on-top --window-title="My device" --stay-awake
goto end
:daily
del "C:\Users\UserName\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt"
echo.
echo "Successfully clean powershell command history !"
echo.
tree /f /a "C:\Users\UserName\AppData\Roaming\Sublime Text\Local\"
echo.
:choose
set /p choice="Remove all files above ? (Y/N):"
echo.
if /i "%choice%"=="Y" goto next_choice_step
if /i "%choice%"=="N" goto end
Echo "Invalid choice ! Press any key to choose again"
echo.
pause>nul&goto choose
:next_choice_step
del /s /q "C:\Users\UserName\AppData\Roaming\Sublime Text\Local\*"
echo.
echo "Successfully clean sublime session history !"
goto end
:error
echo Invalid choice !
goto end
:end
echo.

浙公网安备 33010602011771号