Tag Archives: powershell

Why you should use the Command Line (a lot…)

My office colleague, “R”, is always on my case: “Ha! I’m always amazed to see you using your command line!” Well, remarks like this, kinda make me feel, geeky, but trust me, I’m no nerd – just some curious cat. It may make one look like they have special powers, but I’m just blessed that the first time I started using (or rather, fooling around) with computers, it was at the command line.

It never did much with it, but that start spared me from the irrational trepidation that many people have towards the console. The only DOS commands I knew back then were CD, DIR, TREE and ROBOCOPY – of which I only used the first three. So, I wasn’t really a user. A few years down the line, atrocious internet connections forced me to do ipconfiging and pinging. But that was it. I’m not a Special One.

I use the command line interface (CLI) nowadays for one simple reason: I’m lazy. Maybe I became lazy since I started doing a lot more programming. Nowadays I work principally from Windows Powershell, which is both a CLI and a scripting environment. It can’t get better than this. But here’s why:

    1. It saves me tons of time: After setting up my Powershell profile, whenever I want to read my Bible, I just type in bible. When I want to log onto my WiFi, I pass the instruction smile, and when I’m done I tell my machine to smileoff. How long did it take me to write the script that enables me to do this? Just a few minutes. How much time is it saving me? Cumulatively, hours!

# Alias: smile/smileoff. Command for controlling my personal Wi-Fi
function Connect-Smile
{
    (netsh wlan connect name='Smile@Maverick')
}
New-Alias -Name smile -Value Connect-Smile

# ----------------------------------------#

function Disconnect-Smile
{
    (netsh wlan disconnect)
}
New-Alias -Name smileoff -Value Disconnect-Smile


  1. I have a lot more control over my computer: As one begins to use the command line more often, one gathers more and more experience on its features and the different possibilities. I know feel much more in control when I’m using the computer and I can customise it a lot more, so that it actually is MY computer. As I pick up one or two scripts (or scripting skills) from the internet and apply them to my system, I can make it bend a lot more to my whims and caprices, and also selectively shut out prying eyes.
  2. I gain more expressivity: I read this blog on this issue and I agree with the author – since I started using the command line, almost exclusively, when interacting with the operating system, the mindless mouse clicking has turned into an actual semblance between me and the computer. For good measure, I included a greeting message in my Profile, so whenever I fire up the program, I get this greeting. Are these the beginnings of AI for me (á la Mark)?

Powershell startup with personalised greeting.

  1. I have less stress after upgrades: I remember the jump I had to make from Windows XP/7 and Windows 8. The difference was so clear and the learning curve quite steep. I recall having to make the same leap from Windows 2000 to XP. Why, oh why, Microsoft??? I upgraded to Windows 10 a few months ago, but guess what? I never had to bother about the new interface. I can count on one hand the number of times I have used the Start Menu. When I first saw it I was like “What the heck?! I will operate from my blue screen, thank you very much.” On a serious note, if you can learn to carry out your most mundane tasks and launch your commonly used programs from the command line, you will save yourself hours or even days and weeks of trying to figure out how to use your PC’s GUI after major operating system upgrades because the CLI stays basically the same. This works across platforms to (in a way); the other day a friend asked me to do something on her Mac and being a Mac-ignoramus, I opened the shell, BASH, and worked from there. She was just staring at me with utter amazement!
  2. I can run many programs and utilities in the same window: I discovered this one only recently and I’m exploring it. Just like I mentioned about ipconfig earlier, I found out that I could run Git and R right there in the CLI. So, when I want to just do a quick commit, I run gitcmd, which I pre-configured in my Powershell Profile to run git-cmd.exe. Alternatively, I could have pointed the Git directory to $PATH (for more information on how to do this in Windows, read this article).

This post is getting too long, sorry. There are other benefits you can discover on your own on the internet. All I am saying to those who are so accustomed to clicking-and-pointing: Learn to use command line, especially if you’re a professional or in any kind of technical field. It will save you a lot of hassle once you get the hang of it.

Cheers.

Advertisements

Leave a comment

Filed under Computers & Internet

How I Accidentally Discovered How To Use Git inside Powershell

In the course of my forays into the world of programming (or rather, coding) I have had cause to learn how to use Git for version control (thank you, Linus Torvalds, for this great tool!). Although some of the IDEs that I use (RStudio for R; Visual Studio for C++) have some form of Git integration, I discovered that it’s much better to do my commits, branching, pulling and pushing using the command-line interface (CLI).

Besides all this, I have over time gotten tired of having to learn how to use my graphics user interface (GUI) with every major upgrade, so I just returned to the basics (I learnt computing with MS-DOS) and have settled down with using Windows Powershell to interact with my computer’s operating system. Therefore, whenever I wanted to run Git, I would this (note that anything before the ‘>’ symbol is included in the prompt, while the text on the right hand side is supplied by the user)

PS C:\Users\Admn>
PS C:\Users\Admn> Start-Process .\Downloads\MinGW\Git\git-cmd.exe

Alternatively, rather than use the cmdletStart-Process‘, one could use the alias ‘start‘ and get the same result.
This command opens up Git CMD in a new window. Optionally, one could type git-bash.exe if one wants to use Git Bash, but since I prefer Git CMD, I will focus on that in this post.

I found opening this new window to be cumbersome, since I could as well open the application through the Start Menu by hitting ‘Win-key’ and typing the search term ‘git’. I looked online to see whether there was anything on Git integration with Powershell, but came up empty.

One day, as I was trying to open Git via Powershell, I committed a typo and hit the jackpot! Here is what I discovered: I could open Git CMD right inside Powershell, carry out all the operations I wanted and then exit without having to terminate my Powershell session. This is what to do

PS C:\Users\Admn>
PS C:\Users\Admn> C:Users\Admn\Downloads\MinGW\Git\git-cmd.exe

Note that there is no cmdlet in this instruction. What happens next is that the prompt changes from

PS C:\Users\Admn>

to

C:\Users\Admn>

This means that, effectively, this has ceased to be a Powershell window, but has been transformed to a regular Command Prompt environment. If you navigate to any directory that is a Git repository, the appropriate commands like git status work just fine – which is impossible if you’re using Powershell. When you’re done and your want to return to Powershell, just run exit at the prompt and it will change to the ‘PS’ prefixed state.

Note that for some silly reason, I installed Git in my ‘Downloads’ folder. On another machine, I have it installed in the right place – i.e. Program Files – and when I carried out the above operations using the appropriate file path, the result was the same. I had stumbled upon Git integration in Powershell!

I tried this out with v2.0 and v5.0, so for all intents and purposes, this should work with any Windows machine that has Powershell installed .

Cheers!

1 Comment

Filed under Computers & Internet