Created
July 19, 2023 08:51
-
-
Save PhotonQuantum/03d398addf30b63638f1f52609a6f7ad to your computer and use it in GitHub Desktop.
Genshin Start!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://asciinema.org/a/dEy2ClwENWmJ9NY4jWDzmqnVi