Skip to content

Instantly share code, notes, and snippets.

@PhotonQuantum
Created July 19, 2023 08:51
Show Gist options
  • Save PhotonQuantum/03d398addf30b63638f1f52609a6f7ad to your computer and use it in GitHub Desktop.
Save PhotonQuantum/03d398addf30b63638f1f52609a6f7ad to your computer and use it in GitHub Desktop.
Genshin Start!
#!/usr/bin/env bash
set -e
declare -A replace_map
replace_map["cargo"]="genshin"
replace_map["Cargo"]="Genshin"
replace_map["rust"]="mihoyo"
replace_map["Rust"]="miHoYo"
replace_map["RUST"]="MIHOYO"
declare -A rev_replace_map
for key in "${!replace_map[@]}"; do
rev_replace_map[${replace_map[$key]}]=$key
done
# Generate the sed script
sed_script=""
for key in "${!replace_map[@]}"; do
sed_script+="s/$key/${replace_map[$key]}/g;"
done
# replace all input arguments
command=$@
for i in ${!command[@]}; do
for key in "${!rev_replace_map[@]}"; do
command[$i]=${command[$i]//$key/${rev_replace_map[$key]}}
done
done
# detect if faketty exists
if [ -x "$(command -v faketty)" ]; then
faketty="faketty"
elif [ -x "$(command -v faketty.exe)" ]; then
faketty = ""
fi
$faketty cargo $command 2> >(sed -u "$sed_script" >&2) | sed -u "$sed_script"
@noctoid
Copy link

noctoid commented Jul 19, 2023

原神怎么你了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment