[windows] Aliases in Windows command prompt

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.

Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to alias

How to open google chrome from terminal? Aliases in Windows command prompt SQL alias for SELECT statement How do I run a shell script without using "sh" or "bash" commands? Is the 'as' keyword required in Oracle to define an alias? Make a Bash alias that takes a parameter? List Git aliases How to write UPDATE SQL with Table alias in SQL Server 2008? Should I use alias or alias_method? SQL - using alias in Group By

Examples related to command-prompt

CMD command to check connected USB devices How do I kill the process currently using a port on localhost in Windows? PowerShell The term is not recognized as cmdlet function script file or operable program open program minimized via command prompt How to connect to SQL Server from command prompt with Windows authentication How to see the proxy settings on windows? How do I type a TAB character in PowerShell? Batch file to split .csv file Aliases in Windows command prompt Change all files and folders permissions of a directory to 644/755