我已经在环境变量的路径中添加了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上使用.cmd文件的一个优势是,这些“别名”可以在其他shell中使用,如PowerShell或WSL (Linux的Windows子系统)。
在bash中使用这些命令的唯一缺点是可能需要更多的设置,因为在调用“别名”之前可能需要进行一些路径操作。
我有vs.cmd,这是我在Visual Studio编辑文件的“别名”
@echo off
if [%1]==[] goto nofiles
start "" "c:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\devenv.exe" /edit %1
goto end
:nofiles
start "" "C:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\devenv.exe" "[PATH TO MY NORMAL SLN]"
:end
它会点燃VS(在这种情况下VS2012 -但调整口味)使用我的“正常”项目,没有文件,但当给出一个文件时,将试图附加到一个运行的VS打开该文件“在该项目中”,而不是开始一个新的VS实例。
为了从bash使用这个,我然后添加了一个额外的间接级别,因为“vs Myfile”并不总是工作
alias vs='/usr/bin/run_visual_studio.sh'
在调用vs.cmd之前调整路径
#!/bin/bash
cmd.exe /C 'c:\Windows\System32\vs.cmd' "`wslpath.sh -w -r $1`"
这样我就可以
vs SomeFile.txt
在命令提示符中,Power Shell或bash,它在我运行的Visual Studio中打开进行编辑(当我在VS中编辑了几个小时时,这只是让我可怜的大脑不必处理VI命令或其他类似的命令)。
其他回答
或者你也可以使用cder,它可以让你像linux一样添加别名:
alias subl="C:\Program Files\Sublime Text 3\subl.exe" $*
扩展罗里休伊特的回答。
在DOSKEY上使用.cmd文件的一个优势是,这些“别名”可以在其他shell中使用,如PowerShell或WSL (Linux的Windows子系统)。
在bash中使用这些命令的唯一缺点是可能需要更多的设置,因为在调用“别名”之前可能需要进行一些路径操作。
我有vs.cmd,这是我在Visual Studio编辑文件的“别名”
@echo off
if [%1]==[] goto nofiles
start "" "c:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\devenv.exe" /edit %1
goto end
:nofiles
start "" "C:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\devenv.exe" "[PATH TO MY NORMAL SLN]"
:end
它会点燃VS(在这种情况下VS2012 -但调整口味)使用我的“正常”项目,没有文件,但当给出一个文件时,将试图附加到一个运行的VS打开该文件“在该项目中”,而不是开始一个新的VS实例。
为了从bash使用这个,我然后添加了一个额外的间接级别,因为“vs Myfile”并不总是工作
alias vs='/usr/bin/run_visual_studio.sh'
在调用vs.cmd之前调整路径
#!/bin/bash
cmd.exe /C 'c:\Windows\System32\vs.cmd' "`wslpath.sh -w -r $1`"
这样我就可以
vs SomeFile.txt
在命令提示符中,Power Shell或bash,它在我运行的Visual Studio中打开进行编辑(当我在VS中编辑了几个小时时,这只是让我可怜的大脑不必处理VI命令或其他类似的命令)。
如果你想在每个目录/每个项目的基础上启用别名,试试下面的方法:
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中的内置命令。
我的快速而肮脏的解决方案是在PATH中已经存在的任何目录中添加一个BAT文件。
例子:
@ECHO OFF
doskey dl=aria2c --file-allocation=none $*
aria2c --file-allocation=none %**
因此,第一次运行“dl”时,它将执行bat文件,但从第二次开始,它将使用别名。
你需要传递参数,试试这个:
doskey np=notepad++.exe $*
编辑(回应Romonov的评论)Q:有什么方法可以让命令提示符记住,这样我就不必每次打开新的命令提示符时都运行这个了?
Doskey是一个由命令处理器(例如cmd.exe)解释的文本命令,它不能知道在其他进程(特别是还没有启动的进程)中修改状态。
使用doskey设置初始命令shell环境的人通常使用/K选项(通常通过快捷方式)来运行一个批处理文件,该文件执行所有常见的设置(如-设置窗口的标题,颜色等)。
cmd.exe /K env.cmd
env.cmd:
title "Foo Bar"
doskey np=notepad++.exe $*
...