我已经在环境变量的路径中添加了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++放在前面,而不打开文件。我怎样才能让它打开文件呢?
谢谢。
当前回答
使用doskey是正确的方法,但是当命令提示符窗口关闭时,它会重置。您需要将这一行添加到类似.bashrc的等价文件中。所以我做了以下事情:
将“C:\Program Files (x86)\ notepad++”添加到系统路径变量 复制notepad++.exe(当然,在同一个文件夹中),并将其重命名为np.exe
工作得很好!
其他回答
当然,在我找到最方便的解决办法之前,我是不会休息的。结合大量互联网上的答案和话题,以下是你可以得到的。
自动加载每个实例的cmd 不需要关键字DOSKEY作为别名 示例:ls=ls——color=auto $*
请注意,这很大程度上是基于Argyll的回答和评论,一定要阅读它来理解概念。
如何让它起作用?
创建一个带有别名的mac宏文件 你甚至可以使用bat/cmd文件来运行其他东西(类似于linux中的.bashrc) 在注册表中注册它以在cmd的每个实例上运行 或者只在需要时通过快捷方式运行它
示例步骤:
mac userprofile % - cmd化名之一。
;==============================================================================
;= This file is registered via registry to auto load with each instance of cmd.
;================================ general info ================================
;= https://stackoverflow.com/a/59978163/985454 - how to set it up?
;= https://gist.github.com/postcog/5c8c13f7f66330b493b8 - example doskey macrofile
;========================= loading with cmd shortcut ==========================
;= create a shortcut with the following target :
;= %comspec% /k "(doskey /macrofile=%userprofile%\cmd\aliases.mac)"
alias=echo Opening aliases in Sublime... && subl %USERPROFILE%\cmd\aliases.mac
ga=grep --color "$1" %USERPROFILE%\cmd\aliases.mac
hosts=runas /noprofile /savecred /user:QWERTY-XPS9370\administrator "subl C:\Windows\System32\drivers\etc\hosts" > NUL
p=@echo "~~ powercfg -devicequery wake_armed ~~" && powercfg -devicequery wake_armed && @echo "~~ powercfg -requests ~~ " && powercfg -requests && @echo "~~ powercfg -waketimers ~~"p && powercfg -waketimers
ls=ls --color=auto $*
ll=ls -l --color=auto $*
la=ls -la --color=auto $*
grep=grep --color $*
~=cd %USERPROFILE%
cdr=cd C:\repos
cde=cd C:\repos\esquire
cdd=cd C:\repos\dixons
cds=cd C:\repos\stekkie
cdu=cd C:\repos\uplus
cduo=cd C:\repos\uplus\oxbridge-fe
cdus=cd C:\repos\uplus\stratus
npx=npx --no-install $*
npxi=npx $*
npr=npm run $*
now=vercel $*
;=only in bash
;=alias whereget='_whereget() { A=$1; B=$2; shift 2; eval \"$(where $B | head -$A | tail -1)\" $@; }; _whereget'
history=doskey /history
h=IF ".$*." == ".." (echo "usage: h [ SAVE | TAIL [-|+<n>] | OPEN ]" && echo. && doskey/history) ELSE (IF /I "$1" == "OPEN" (%USERPROFILE%\cmd\history.log) ELSE (IF /I "$1" == "SAVE" (echo **** %date% %time% **** >> %USERPROFILE%\cmd\history.log & doskey/history >> %USERPROFILE%\cmd\history.log & ECHO Command history saved) ELSE (IF /I "$1" == "TAIL" (tail $2 %USERPROFILE%\cmd\history.log) ELSE (doskey/history))))
;=exit=echo **** %date% %time% **** >> %USERPROFILE%\cmd\history.log & doskey/history >> %USERPROFILE%\cmd\history.log & ECHO Command history saved, exiting & timeout 1 & exit $*
exit=echo **** %date% %time% **** >> %USERPROFILE%\cmd\history.log & doskey/history >> %USERPROFILE%\cmd\history.log & exit $*
;============================= :end ============================
;= rem ******************************************************************
;= rem * EOF - Don't remove the following line. It clears out the ';'
;= rem * macro. We're using it because there is no support for comments
;= rem * in a DOSKEY macro file.
;= rem ******************************************************************
;=
现在你有三个选择:
A)手动加载快捷方式 用以下目标创建cmd.exe的快捷方式: %comspec% /k "(doskey /macrofile=%userprofile%\cmd\alias .mac)" B)只注册别名。mac macrofile C)注册一个常规的cmd/bat文件来运行任意命令(类似于linux的.bashrc) 参见示例cmdrc。CMD文件在底部
注意:下面,Autorun_只是一个占位符键,不会做任何事情。选择一个并重命名另一个。
手动编辑注册表在这个路径:
(微软HKEY_CURRENT_USER \ Software \ \命令处理器)
Autorun REG_SZ doskey /macrofile=%userprofile%\cmd\aliases.mac
Autorun_ REG_SZ %USERPROFILE%\cmd\cmdrc.cmd
或导入reg文件:
userprofile % - cmd cmd-aliases reg。
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"Autorun"="doskey /macrofile=%userprofile%\\cmd\\aliases.mac"
"Autorun_"="%USERPROFILE%\\cmd\\cmdrc.cmd"
% userprofile % / cmd / cmdrc。CMD你不需要这个文件,如果你决定b)以上
:: This file is registered via registry to auto load with each instance of cmd.
:: https://stackoverflow.com/a/59978163/985454
@echo off
doskey /macrofile=%userprofile%\cmd\aliases.mac
:: put other commands here
cls
echo Hi Qwerty, how are you today?
实际上,我要给你一个更好的,让你知道一个小技巧,自从我以前在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.
由于doskey不适用于PowerShell或Windows 10终端应用程序,我将分享这个解决方案。
演示如何在Windows 10中创建别名。输入参数的别名:
com=D:\website_development\laragon\bin\php\php-8.1.2-Win32-vs16-x64/php8 D:\website_development\laragon\bin\composer/composer.phar
过程:
在C:驱动器中创建一个名为scripts的文件夹。 在scripts文件夹中,创建com.bat 打开com.bat 使用特定PHP版本运行composer命令的示例: @echo掉 设置路径=D:\website_development\laragon\bin\php\php-8.1.2- win32 -vs16-x64/php8 设置参数= % * 设置命令=%path% %args% 命令% % 保存它 点击“开始” 搜索“编辑环境变量” 点击“高级” 将“scripts”目录添加到PATH。
现在您可以作为该命令的别名运行该命令。
注意:如果你想添加一个新的别名,只需创建一个新的bat文件。
如果你想在每个目录/每个项目的基础上启用别名,试试下面的方法:
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中的内置命令。
或者你也可以使用cder,它可以让你像linux一样添加别名:
alias subl="C:\Program Files\Sublime Text 3\subl.exe" $*