Getting The Most From Your CMD Line
There are those of us that actually perform web development tasks on a Windows machine. GASP! I know, right! But in all seriousness, it's true. Myself included. I could go through the varies different reasons, but who cares. That's not what this post is about. It's about getting the most out of the Windows command line as possible.
Now if you are a PuTTY user, then you might not get a lot out of this post, so you might want to move along. If not, and your using GIT's Bash shell utility, which is based on MINGW32, or maybe Cygwin, you very well might still get a few tricks. I don't have any real experience with Cygwin, so... not sure how well this will travel.
Copy & Paste
We all know how helpful it is to have the ability to copy content from one place, then paste it somewhere else. But, in the native Windows Command line or MINGW32... not so much. Actually, it's pretty freaking frustrating. Luckily, this is not too hard to solve.
- Open your CMD Line and click in the upper left corner.
- In the menu, select "Defaults"
- In the window that opens, look for the "Edit Options" pane.
- Select "Quick Edit Mode" & "Insert Mode"
Quick Edit Mode
This allows you to easily paste content into the cmd line by a simple right click. To me, this is the single most important tip of them all. Given that you do not employ any other suggestion from this post but this one, and you are not currently doing this, it will not even bother you that you did not read the rest of the post.
This also enables use to do is easily copy content out of the command line, which is freaking brilliant! Let me demonstrate...
What I am doing here is as follows:
- Click and drag box around area of content you need.
- Press Enter to copy to content to clipboard.
- CTR-V clipboard content to where ever.
Not the best solution, but still pretty handy. Those of use who do not use VIM everyday, find the key commands to be some of the most confusing things this side of particle physics. Actually, that makes more sense now that I give it some thought. But, I am actually copy content out of VIM and into NOTEPAD, so... that alone is pretty powerful.
Nothing overly fancy, but something you will want to check as well. Basically, it allows QuickEditMode to insert whatever content you have at the point of your cursor. Not having this checked will result in anything you have typed already being overwritten by the pasted content. So, just make sure it's checked, ok!
Some already know this one, but you actually have a command history built into your command line. It can be accessed in a few different ways, with the arrow keys(↑ and ↓). To go back to your last command, just press the ↑ arrow. Keep pressing it to go even further back. Use the ↓ to backwards in the list, in case you missed the command you was looking for.
This is nice and all, but there is actually a cooler way you can go about this. It's called the Command Menu and from what I can tell, it only works in the native Windows Cmd Prompt and Powershell. I tried this in GIT Bash, but no go, so... unless some knows something that I couldn't find, please post it in the comments below.
For this to work, just hit the "F7" key and a menu will be displayed showing all the commands in your command history. And yes, you use the up and down arrows to make your selection. Followed by pressing "Enter" to execute that command.
Notice in the above example that I am issuing the command ls show that I can expose my directory structure, then changing into the directory of my choice. Well, instead of eating up my command line real estate (yeah, I think I just made that up), I can type cd followed by pressing the TAB key and this will scroll through the list of directories found. If you skim past the file or directory your looking for, just Shift-TAB backwards through the list.
Drag and Drop
Who knew that a tool and old an antiquated as the Windows command line would support Drag and Drop? But it does! Basically, you drag a file from Windows Explorer or your desktop into the command window and the full path to that file is copied into the command line. Check it out...
Well, this is actually just the tip of the iceberg. But these are some of the techniques I use everyday when I code. I hope someone can take one, two or even all of these tips and walk away with something to make themselves more productive. And who doesn't like being more productive?
Do you have some tips/tricks/hacks for Powershell, Windows Prompt, MingW32 or others? Post a comment and share them. Maybe we can put something together to document them all. Who knows?