Win command-line

2011-05-01 cmd windows doskey autorun msdn keyboard

Some notes on how to better utilize Windows command-line.

AutoRun

Here is how to setup what commands to run after cmd.exe runs.

To check what is currently setup there:

reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor" /v AutoRun
reg query "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun

An example to set command prompt to $ :

reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "prompt $$$S"

or set the prompt to yellow color (the guide for esc codes):

reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "prompt $e[93m$P$G$e[0m"

Pager

Many commands can benefit from setting PAGER variable to something more elaborate than more command. I have it set to less -S, where less is windows port of linux less command. It allows to scroll back and forth all the contents, search in it and many other useful commands.

Less is a free, open-source file pager. It can be found on most versions of Linux, Unix and Mac OS, as well as on many other operating systems.

When installed, run

less --help

to see all instructions and options.

doskey

recalls previously entered command-line commands, edits command lines, and creates macros

doskey reference on MSDN

Useful commands

Command What it does
doskey /history dump history to stdout
doskey mc=md $1$tcd $1 creates macro mc that creates directory and enters it

useful keys

Key What it does
Up/Down/PgUp/PgDn going around history
Home/End move to start/end of line
Left/Right move by one character
Ctrl+Left/Ctrl+Right move by words
Ctrl+End delete to end of line
F5 recall previous command to editing
F7 list of previous commands
Alt+F7 clears history
F8 complete line from history
F9 pick command from history by number
Tab complete filename/dirname from current directory