我已经在环境变量的路径中添加了notepad++.exe。
现在在命令提示符中,notepad++.exe filename.txt打开filename.txt。但我想用np filename。txt来打开文件。
我尝试使用DOSKEY np=notepad++。但它只是把一个已经打开的notepad++放在前面,而不打开文件。我怎样才能让它打开文件呢?
谢谢。
我已经在环境变量的路径中添加了notepad++.exe。
现在在命令提示符中,notepad++.exe filename.txt打开filename.txt。但我想用np filename。txt来打开文件。
我尝试使用DOSKEY np=notepad++。但它只是把一个已经打开的notepad++放在前面,而不打开文件。我怎样才能让它打开文件呢?
谢谢。
当前回答
实际上,我要给你一个更好的,让你知道一个小技巧,自从我以前在Amiga上编程时,我就用过。在您使用的任何新系统上,无论是个人系统还是专业系统,第一步都是创建两个文件夹:C:\BIN和C:\BATCH。然后修改路径语句,将两者放在开头的顺序C:\BATCH;C:\BIN;[剩余的路径]。
完成这些后,如果你有一些需要访问的实用程序,只需将它们复制到C:\BIN文件夹,它们就在你的路径中。要临时覆盖这些赋值,您可以将一个与可执行文件同名的批处理文件添加到C:\ batch文件夹中,路径将在C:\BIN文件之前找到它。它应该涵盖你可能需要做的任何事情。
Of course, these days the canonical correct way to do this would be to create a symbolic junction to the file, but the same principle applies. There is a little extra added bonus as well. If you want to put something in the system that conflicts with something already in the path, putting it in the C:\BIN or C:\Batch folder will simply pre-empt the original - allowing you to override stuff either temporarily or permanently, or rename things to names you're more comfortable with - without actually altering the original.
其他回答
Windows 10中的控制台别名
要定义控制台别名,请使用Doskey.exe创建宏,或使用AddConsoleAlias函数。
dos命令
doskey test=cd \a_very_long_path\test
还要在最后传递参数:doskey short=longname $*
添加控制台别名
AddConsoleAlias( TEXT("test"),
TEXT("cd \\<a_very_long_path>\\test"),
TEXT("cmd.exe"));
更多信息在这里控制台别名,Doskey,参数
非常简单的自定义别名:
在系统的任何地方创建一个专门用于别名的新文件夹。创建一个新文件,命名为你想命名的别名,扩展名为.cmd。将所有命令写入文件,例如
cd /D D:\Folder
g++ -o run something.cpp
复制文件夹的路径。
>系统>关于>系统高级设置>环境变量…
现在在System variables部分中找到Path变量。单击它一次,然后单击Edit。现在单击New并粘贴复制的文本。
单击“确定”、“确定”和“确定”。重新启动Powershell/cmd提示符,瞧,您得到了持久的别名!您也可以使用相同的文件夹来创建其他别名,而无需再次更改Path变量!
我的快速而肮脏的解决方案是在PATH中已经存在的任何目录中添加一个BAT文件。
例子:
@ECHO OFF
doskey dl=aria2c --file-allocation=none $*
aria2c --file-allocation=none %**
因此,第一次运行“dl”时,它将执行bat文件,但从第二次开始,它将使用别名。
实际上,我要给你一个更好的,让你知道一个小技巧,自从我以前在Amiga上编程时,我就用过。在您使用的任何新系统上,无论是个人系统还是专业系统,第一步都是创建两个文件夹:C:\BIN和C:\BATCH。然后修改路径语句,将两者放在开头的顺序C:\BATCH;C:\BIN;[剩余的路径]。
完成这些后,如果你有一些需要访问的实用程序,只需将它们复制到C:\BIN文件夹,它们就在你的路径中。要临时覆盖这些赋值,您可以将一个与可执行文件同名的批处理文件添加到C:\ batch文件夹中,路径将在C:\BIN文件之前找到它。它应该涵盖你可能需要做的任何事情。
Of course, these days the canonical correct way to do this would be to create a symbolic junction to the file, but the same principle applies. There is a little extra added bonus as well. If you want to put something in the system that conflicts with something already in the path, putting it in the C:\BIN or C:\Batch folder will simply pre-empt the original - allowing you to override stuff either temporarily or permanently, or rename things to names you're more comfortable with - without actually altering the original.
如果你想在每个目录/每个项目的基础上启用别名,试试下面的方法:
First, create a batch file that will look for a file named aliases in the current directory and initialize aliases from it, let’s call it make-aliases.cmd @echo off if not exist aliases goto:eof echo [Loading aliases...] for /f "tokens=1* delims=^=" %%i in (aliases) do ( echo %%i ^<^=^> %%j doskey %%i=%%j ) doskey aliases=doskey /macros echo -------------------- echo aliases ^=^> list all echo alt+F10 ^=^> clear all echo [Done] Then, create aliases wherever you need them using the following format: alias1 = command1 alias2 = command2 ... for example: b = nmake c = nmake clean r = nmake rebuild Then, add the location of make-aliases.cmd to your %PATH% variable to make it system-wide or just keep it in a known place. Make it start automatically with cmd. I would definitely advise against using HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun for this, because some development tools would trigger the autorun script multiple times per session. If you use ConEmu you could go another way and start the script from the startup task (Settings > Startup > Tasks), for example, I created an entry called {MSVC}: cmd.exe /k "vcvars64 && make-aliases", and then registered it in Explorer context menu via Settings > Integration> with Command: {MSVC} -cur_console:n, so that now I can right-click a folder and launch a VS developer prompt inside it with my aliases loaded automatically, if they happen to be in that folder. Without ConEmu, you may just want to create a shortcut to cmd.exe with the corresponding command or simply run make-aliases manually every time.
如果你碰巧忘记了你的别名,使用aliases宏,如果出现任何问题,只需按Alt+F10重置当前会话,这是cmd中的内置命令。