Answers:
多亏了引力的doskey宏,它才能正常工作。他使用&&组合了cd和title命令,效果很好。每次使用cmd时,我都通过调整注册表来使此宏加载。
1)我创建了一个名为cmd_title.bat的蝙蝠文件,其内容为
@echo off
title %cd%
2)我将此文件放在C:驱动器(C:\ cmd_title.bat)中
3)在C:驱动器中创建另一个名为cmd.bat的批处理文件,其内容如下:
doskey cd = cd /d $* ^&^& "C:\cmd_title.bat"
title %cd%
(/ d标志用于使用cd切换到另一个驱动器)。
4)然后我们打开regedit并转到HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Command Processor。这里有一个称为AutoRun的键。我们修改该键的值,并将其设置为cmd.bat文件中带引号的位置(例如:“ C:\ cmd.bat”)。
现在,每次打开cmd时,cd就可以按照我们的要求工作。
基本上&&用于Windows中的命令链接
doskey cd=@echo off$Tcd /d $*$T@title ^%cd^%$Techo on
@echo off
没有必要,只要@
在不想回显的命令前面添加即可。我还发现此命令对于将标题设置为仅当前目录名而不是完整路径更为有用@for %%* in (.) do @title %%~nx*
我认为push和popd比cd有用,并且如果它们能更快键入,将会看到更多的用途。我已使用以下脚本解决了cd vs. push / popd和控制台窗口目录标题的问题,该脚本称为d.bat,位于我的路径中。
@ echo off
rem d.bat replaces CD, PUSHD, and POPD with one command that also changes the title
rem of the console window to tell the current directory. Invoked with no arg, the
rem title is updated. Use this after changing the directory by some other means.
rem The argument / invokes popd. Any other argument invokes pushd with that arg.
if not _%1 == _ (
if _%1 == _/ (
popd
) else (
pushd %*
)
)
title %CD%
您可以使用命令更改命令提示符的标题title
。
您可以创建一个包含以下内容的批处理文件(例如mycd.bat):
title "%1"
cd "%1"
并使用它代替“ cd”:
mycd "newdir"
如果您希望它始终可用,也可以将.bat文件放在system32中。
doskey cd=cd $* ^&^& title $*
您不能,至少不能使用Windows Shell。
这也许有可能加入“集的Xterm标题”转义序列%PROMPT%
,但你需要一个不同的终端仿真器(可能是PuTTYcyg或东西从SFU),因为Windows控制台不支持转义序列。
或者,找到另一个可以使用Windows控制台功能设置标题的外壳。
这些通常在Windows上下文中很困惑,所以...
Shell读取和解释输入;cmd.exe
,command.com
,/bin/sh
terminal,终端仿真器,控制台在屏幕上显示基于文本的程序(包括外壳);Windows Console
,xterm
,PuTTYcyg
explorer
是一个GUI Shell,cmd.exe
是一个基于文本的外壳。(考虑一下:在Unix中cmd.exe
与之完全等效/bin/sh
,并且/bin/sh
始终称为“外壳”。类似地,Windows控制台在X11中等同于“终端仿真器”。)
pushd
其中一个宏时会发生什么?