PowerShell Profile Shortcuts
Learn some handy PowerShell shortcuts and workarounds to make customizing your profile an easier process.
Join the DZone community and get the full member experience.Join For Free
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.
Published at DZone with permission of Daniel Egan, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.