Search Google from the powershell console
You may have seen people walking around with those awkwardEat; Sleep; Code; Repeat;
brogrammer shirts. I don’t like them - between the many other things that developing software requires, when I actually sit down to write code the workflow would more accurately be described as Code; Compile; Google Error; Repeat;
.
This short post explains how the below gg.ps1
Powershell script can increase your productivity by opening a chrome browser and executing a Google search straight from the Powershell console.
If no arguments are passed to the function, it will Google whatever is in the clipboard, reducing keystrokes required to ctrl+c
,gg
,enter
.
# Function name is used to call the function after importing this script
Function gg
{
<# .Synopsis
Open Chrome browser and search for the [-SearchString] argument.
If [-SearchString] not provided, defaults to clipboard contents.
Requires Google Chrome browser to be installed with "chrome.exe" in the system path.
Example usage:
gg "your search terms"
#>
param (
[parameter(mandatory=$false, Position=0)] `
[String]$SearchString
)
process {
if (!$SearchString){
$SearchString = Get-Clipboard;
}
$URL = $SearchString -replace ' ','+';
$URL = "https://www.google.com/search?q=" + $URL;
echo ("Searching Google for <" + $SearchString + ">...");
start chrome.exe $URL;
}
}
To automatically import this function whenever Powershell is started, see my post “Use Powershell Profiles Like a Pro”.