Powershell profile shortcuts

powershellicon

Since I have been using the MEAN stack and node quite a bit lately, I have found my self to be using the command line all of 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 (you can find it at http://www.cmder.net ).  I will do another post as to why  I like it but in this post I wanted to show you just a few of the things I have added to make life easier from the command line.

 

First, cmder uses conemu ( https://conemu.github.io/ ) 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.

  1. start up in the folder that I choose
  2. 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

psprofilepic1
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 like http://www.network-science.de/ascii/

Here is what it looks like when PowerShell starts.

newcommand

The next thing I wanted was the ability to create a directory and cd into it at the same time, which you can on mac terminal or Linux using the && characters. PowerShell does not like the  && characters.

So for this I created a function called mcd in which I pass the name of the folder I want to create.

mcd

 

 

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 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 http://www.codefoster.com who has helped me with everything commandline.. thanks Jeremy)

clfunction

Finally, the last one I will show you is just launching a browser.  Since I am working with node all of 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 a ability to name the port I wanted.

launchbrosers
That way I can easily type something like chromelocal 8000  to launch the browser and get to testing things out.

Anyway, that’s all I wanted to share of my profile for now.  Hope this helps someone.

Daniel – TheSociableGeek