Since I have been using the MEAN stack and node quite a bit lately, I have found myself using the command line all the time. Not just in using node and git, but also to create files (Touch), launch my editor (code or subl), and work with MongoDB (Mongo). My command line of choice for my Windows machines is cmder. I will make another post explaining why I like it, but in this post, I wanted to show you just a few of the things I've added to make life easier from the command line.
First, cmder uses conemu, which is not a shell but adds features to the shell you prefer to use—in this case, PowerShell. The small additions to my profile that I am going to show you will work with PowerShell and so, in essence, with cmder.
The first one is purely cosmetic. When I load up PowerShell, I want it to do two things.
- Start up in the folder that I choose
- Show my branding on top of the screen
In PowerShell, anything not wrapped in a function will run when PowerShell is loaded. So at the top of my profile file, I have the following
When I start up PowerShell, it is branded with TheSociableGeek on top and starts in my c:\projects folder. To create the ASCII text, you can use any online ASCII art editor, such as this one from Network Science.
Here's what it looks like when PowerShell starts.
The next thing I wanted was the ability to create a directory and cd into it at the same time, which you can do on Mac Terminal or Linux using the && characters. PowerShell, however, does not like &&.
So for this I created a function called mcd, in which I pass the name of the folder I want to create.
As you can see, running the mcd command just calls the md (make directory) and cd (change directory) commands with the name I pass it.
Next, one of the things that happens all the time is that I use the clear command when the command window gets too cluttered. I wanted something that not only cleared the window but also put my branding back up at the top like it does when it starts. Again, purely cosmetic, but I like it.
So I created a function called cl that clears the screen and prints out the ASCII again. I know, I could have used a variable and used this for both start up and the cl function, but I was lazy. (I also stole this idea from Jeremy Foster, who has helped me with everything command line. Thanks, Jeremy.)
Finally, the last one I will show you is just launching a browser. Because I'm working with node all the time, I wanted a quick way to launch the browser from the command line. I am not always using browsersync in my projects or demos, so I wanted a quick way to launch different browsers. I created two functions for each browser. One for a default URL, and the other to open a localhost port with the ability to name the port I wanted.
Anyway, that’s all I wanted to share of my profile for now. Hope this helps someone.