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.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'run.sh') 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