-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bing.ps1
54 lines (47 loc) · 1.93 KB
/
bing.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
param([switch]$VerboseSwitch = $false)
# $Verbose=$true -or $VerboseSwitch
$Verbose=$VerboseSwitch
# Write-Verbose "[$script] [$env:SnippetsInitialized] -not `$env:SnippetsInitialized: $(-not $env:SnippetsInitialized)" -Verbose:$Verbose
$script = $MyInvocation.MyCommand
if(-not $env:SnippetsInitialized) {
$fileInfo = New-Object System.IO.FileInfo (Get-Item $PSScriptRoot).FullName
$path = $fileInfo.Directory.FullName;
. $path/Snippets/_common.ps1;
Initialize-Snippets -Verbose:$Verbose
}
try {
$dnScript = Get-Command dotnet-script -ErrorAction SilentlyContinue
if (-not $dnScript) {
& dotnet tool install dotnet-script -g
$dnScript = Get-Command dotnet-script -ErrorAction SilentlyContinue
}
if (-not $dnScript) {
Write-Host "Cannot install dotnet-script"
}
else {
$env:dnscriptPath = $dnScript.Source
if($env:Dotnet) {
$env:dnscriptPath = $env:dnscriptPath.Replace("$env:USERPROFILE\.dotnet", $env:Dotnet).Replace("$env:USERPROFILE/.dotnet", $env:Dotnet)
}
$env:BingLocation = $env:Snippets
if (-not $env:BingLocation.EndsWith("Snippets")) { $env:BingLocation = Join-Path $env:BingLocation -Child "Snippets" }
Write-Verbose "[$script] `$env:BingLocation: $env:BingLocation" -Verbose:$Verbose
$ApiKey = '3c7e251544ba414cbeacad9db55bdf6e'
$env:BingApiKey = $ApiKey
function Search-Bing {
$query = [System.String]::Join(' ', $args);
$csxPath = Join-Path $env:BingLocation -Child 'bing.csx' ;
Write-Verbose "[$script] & $env:dnscriptPath $csxPath `"$query`" --max=3" -Verbose:$Verbose
& $env:dnscriptPath $csxPath "$query" --max=3 --no-cache
}
$alias = set-alias -Verbose:$Verbose -Scope Global -Description "Snippets: [search] Search Bing" -Name bing -Value Search-Bing -PassThru
return "Search Bing by typing ``bing SEARCH``"
}
}
catch {
Write-Host $Error
}
finally {
Write-Verbose '[bing.ps1] Leaving...' -Verbose:$Verbose
$Verbose = $VerboseSwitch
}