PowerShell/Scripts/what-is.ps1

37 lines
1.0 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2023-03-28 11:24:49 +02:00
Explains an abbreviation
2021-07-13 21:10:02 +02:00
.DESCRIPTION
2023-08-18 19:07:48 +02:00
This PowerShell script queries the meaning of the given abbreviation and prints it.
2022-12-21 08:14:30 +01:00
.PARAMETER abbr
2023-08-18 19:07:48 +02:00
Specifies the abbreviation to query
2021-07-13 21:10:02 +02:00
.EXAMPLE
2023-08-18 19:07:48 +02:00
PS> ./what-is VTOL
💡 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
#>
2022-12-21 08:14:30 +01:00
param([string]$abbr = "")
2021-11-28 11:57:49 +01:00
2021-04-27 15:54:52 +02:00
try {
2023-08-18 19:07:48 +02:00
if ($abbr -eq "" ) { $abbr = Read-Host "Enter the abbreviation to query" }
$files = (Get-ChildItem "$PSScriptRoot/../Data/Abbr/*.csv")
$basename = ""
foreach($file in $files) {
$table = Import-CSV "$file"
foreach($row in $table) {
if ($row.ABBR -ne $abbr) { continue }
$basename = (Get-Item "$file").Basename -Replace "_"," "
"💡 $($row.ABBR) in $basename refers to: $($row.MEANING)"
2021-04-27 15:54:52 +02:00
}
}
2023-09-11 10:56:09 +02:00
if ($basename -eq "") { "🤷‍ Sorry, no '$abbr' entry found in my abbrevation tables (located at .../Data/Abbr/)." }
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
}