PowerShell/scripts/what-is.ps1

37 lines
1.1 KiB
PowerShell
Raw Normal View History

2023-10-31 13:03:45 +01:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2024-02-12 15:13:52 +01:00
Explains a term/abbreviation/etc.
2021-07-13 21:10:02 +02:00
.DESCRIPTION
2024-02-12 15:13:52 +01:00
This PowerShell script queries the meaning of the given term/abbreviation/etc. and prints it.
.PARAMETER term
Specifies the term to query
2021-07-13 21:10:02 +02:00
.EXAMPLE
2023-08-18 19:07:48 +02:00
PS> ./what-is VTOL
2023-10-18 17:22:03 +02:00
💡 VTOL in aviation refers to Vertical Take-Off and Landing
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-30 10:49:30 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2021-04-27 15:54:52 +02:00
#>
2024-02-12 15:13:52 +01:00
param([string]$term = "")
2021-11-28 11:57:49 +01:00
2021-04-27 15:54:52 +02:00
try {
2024-02-12 15:13:52 +01:00
if ($term -eq "" ) { $term = Read-Host "Enter the term/abbreviation/etc. to query" }
2024-02-26 16:03:19 +01:00
$files = (Get-ChildItem "$PSScriptRoot/../data/dicts/*.csv")
2023-08-18 19:07:48 +02:00
$basename = ""
foreach($file in $files) {
$table = Import-CSV "$file"
foreach($row in $table) {
if ($row.TERM -ne $term) { continue }
2023-08-18 19:07:48 +02:00
$basename = (Get-Item "$file").Basename -Replace "_"," "
"💡 $($row.TERM) in $basename refers to: $($row.MEANING)"
2021-04-27 15:54:52 +02:00
}
}
2024-02-13 08:15:35 +01:00
if ($basename -eq "") { "🤷‍ Sorry, no '$term' entry found. Use <Ctrl> <Click> to google it: https://www.google.com/search?q=what+is+$term" }
2021-09-27 10:09:45 +02:00
exit 0 # success
2021-04-27 15:54:52 +02:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-04-27 15:54:52 +02:00
exit 1
2023-02-17 14:44:58 +01:00
}