有的时候需要使用一些命令行命令或者通过命令行对环境进行设置。
具体的操作可能并不很复杂,但是对于普通用户来说记住如何操作,或者把如何操作写到笔记里,或者临时搜索,都是比较不方便的做法。
因此我提出了这样的破局方法:
让ai把功能写到bat文件中,bat文件所在目录放到path环境变量中,在命令行中直接调用bat从而实现快速设置。
比如我需要为cmd临时打开proxy,所以找gemini写了一个bat,提示词写一个bat,我可以在cmd中通过调用这个bat,临时设置cmd是否使用proxy但是不影响全局设置
生成的代码如下:
@echo off
rem =================================================================
rem == CMD Proxy Management Script (proxy.bat)
rem == Usage: proxy [on | off | status]
rem =================================================================
:: --- !!! 用户配置区 !!! ---
:: --- 请将下面的地址和端口修改为你自己的代理服务器 ---
rem set PROXY_URL=http://127.0.0.1:7890
set PROXY_URL=127.0.0.1:7890
:: ----------------------------------------------------
:: 检查命令参数 (on, off, status),不区分大小写
if /i "%1"=="on" goto setProxy
if /i "%1"=="off" goto unsetProxy
if /i "%1"=="status" goto checkStatus
:: 如果参数无效或为空,显示帮助信息
goto showHelp
:setProxy
echo Enabling proxy...
set http_proxy=%PROXY_URL%
set https_proxy=%PROXY_URL%
echo.
echo Proxy has been SET for this CMD session.
echo http_proxy = %http_proxy%
goto :eof
:unsetProxy
echo Disabling proxy...
set http_proxy=
set https_proxy=
echo.
echo Proxy has been UNSET for this CMD session.
goto :eof
:checkStatus
echo --- Checking Current Proxy Status ---
if defined http_proxy (
echo [ON] Proxy is currently active.
echo http_proxy = %http_proxy%
echo https_proxy = %https_proxy%
) else (
echo [OFF] Proxy is not set.
)
echo -----------------------------------
goto :eof
:showHelp
echo.
echo Proxy Management Script
echo -------------------------
echo Usage: proxy [command]
echo.
echo Commands:
echo on - Activates the proxy for the current session.
echo off - Deactivates the proxy.
echo status - Shows the current proxy status.
echo.
goto :eof
效果如下:
C:\Windows\System32>proxy
Proxy Management Script
-------------------------
Usage: proxy [command]
Commands:
on - Activates the proxy for the current session.
off - Deactivates the proxy.
status - Shows the current proxy status.
C:\Windows\System32>proxy on
Enabling proxy...
Proxy has been SET for this CMD session.
http_proxy = 127.0.0.1:7890
类似的还有把参数固化到脚本、把参数调用的程序封装为交互式脚本