From 68010bd9b4e3b39ad0306366a95c91ebd57eecf6 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 2 Jul 2026 15:13:07 +0800 Subject: feat: add fuzzy target name matching and display name formatting Normalize user input by removing separators (spaces, underscores, dots, hyphens) and ignore case when looking up targets. Display names in the list menu with spaces instead of underscores or hyphens for readability. --- run.ps1 | 20 +++++++++++++++++--- run.sh | 20 +++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/run.ps1 b/run.ps1 index 782fd46..f0c3652 100644 --- a/run.ps1 +++ b/run.ps1 @@ -96,7 +96,8 @@ if ($args.Count -eq 0) { "nim" { "Nim" } "exe" { "Binary" } } - $entry = " " + $i.ToString().PadRight($num_w) + ") " + $name.PadRight($max_name) + " [$lang]" + $displayName = $name -replace '[_\-]', ' ' + $entry = " " + $i.ToString().PadRight($num_w) + ") " + $displayName.PadRight($max_name) + " [$lang]" Write-Host ("│" + $entry.PadRight($inner_w) + "│") $i++ } @@ -120,8 +121,21 @@ if ($target_name -match '^\d+$') { } if (-not $tools.ContainsKey($target_name)) { - Write-Host "Error: target '$target_name' does not exist" - exit 1 + $normalized = $target_name.ToLower() -replace '[ _\-\.]', '' + $found = $null + foreach ($key in $tools.Keys) { + $keyNormalized = $key.ToLower() -replace '[ _\-\.]', '' + if ($normalized -eq $keyNormalized) { + $found = $key + break + } + } + if ($found) { + $target_name = $found + } else { + Write-Host "Error: target '$target_name' does not exist" + exit 1 + } } $script_args = $args[1..$args.Count] diff --git a/run.sh b/run.sh index 13ee953..4375c32 100755 --- a/run.sh +++ b/run.sh @@ -114,7 +114,8 @@ if [ $# -eq 0 ]; then nim) lang="Nim";; binary) lang="Binary";; esac - entry=$(printf " %-*d) %-*s [%s]" $num_w $i $max_name $name $lang) + display_name=$(echo "$name" | tr '_-' ' ') + entry=$(printf " %-*d) %-*s [%s]" $num_w $i $max_name "$display_name" $lang) printf "│%-*s│\n" $inner_w "$entry" i=$((i + 1)) done @@ -139,8 +140,21 @@ if [[ "$target_name" =~ ^[0-9]+$ ]]; then fi if [ -z "${tools[$target_name]}" ]; then - echo "Error: target '$target_name' does not exist" - exit 1 + normalized_user=$(echo "$target_name" | tr '[:upper:]' '[:lower:]' | sed 's/[_. -]//g') + found="" + for existing_name in "${!tools[@]}"; do + normalized_existing=$(echo "$existing_name" | tr '[:upper:]' '[:lower:]' | sed 's/[_. -]//g') + if [ "$normalized_user" = "$normalized_existing" ]; then + found="$existing_name" + break + fi + done + if [ -n "$found" ]; then + target_name="$found" + else + echo "Error: target '$target_name' does not exist" + exit 1 + fi fi type="${tools[$target_name]}" -- cgit