Aliases in Windows command prompt

后端 未结 16 2494
故里飘歌
故里飘歌 2020-11-22 10:47

I have added notepad++.exe to my Path in Environment variables.

Now in command prompt, notepad++.exe filename.txt opens the filename

16条回答
  •  盖世英雄少女心
    2020-11-22 11:18

    If you'd like to enable aliases on per-directory/per-project basis, try the following:

    1. 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]
      
    2. 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
      
    3. 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.

    4. 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.

    Should you happen to forget your aliases, use the aliases macro, and if anything goes wrong, just reset the current session by pressing Alt+F10, which is a built-in command in cmd.

提交回复
热议问题