Upload files to "/"

This commit is contained in:
sharings 2025-07-24 02:56:54 +08:00
commit b5d7b79d84

157
rime-autogen-script.sh Normal file
View file

@ -0,0 +1,157 @@
#!/usr/bin/env bash
# see man tput, man terminfo
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
GIT_REPOS=(
https://github.com/rime/rime-prelude
https://github.com/rime/rime-essay
https://github.com/rime/rime-cantonese
https://github.com/rime/rime-cangjie
https://github.com/rime/rime-quick
https://github.com/rime/rime-stroke
https://github.com/philipposkhos/rime-ms-quick
https://github.com/kennethso168/rime-cangjie3-extension
)
REQUIRED_FILES_RIME_PRELUDE=(
"default.yaml"
"key_bindings.yaml"
"punctuation.yaml"
"symbols.yaml"
)
REQUIRED_FILES_RIME_ESSAY=(
"essay.txt"
)
REQUIRED_FILES_RIME_CANTONESE=(
"essay-cantonese.txt"
"jyut6ping3.chars.dict.yaml"
"jyut6ping3.dict.yaml"
"jyut6ping3.lettered.dict.yaml"
"jyut6ping3.maps.dict.yaml"
"jyut6ping3.phrase.dict.yaml"
"jyut6ping3.schema.yaml"
"jyut6ping3.words.dict.yaml"
"jyut6ping3_ipa.schema.yaml"
"opencc/" # This is a forder
"symbols_cantonese.yaml"
)
REQUIRED_FILES_RIME_CANGJIE=(
"cangjie5.dict.yaml"
"cangjie5.schema.yaml"
"cangjie5_express.schema.yaml"
)
REQUIRED_FILES_RIME_QUICK=(
"quick5.dict.yaml"
"quick5.schema.yaml"
)
REQUIRED_FILES_RIME_STROKE=(
"stroke.dict.yaml"
"stroke.schema.yaml"
)
REQUIRED_FILES_RIME_MS_QUICK=(
"ms_quick.dict.yaml"
"ms_quick.schema.yaml"
"quickcang5.jyut.dict.yaml"
"quickcang5.simp_voc.dict.yaml"
"quickcang5.voc_luna.dict.yaml"
)
REQUIRED_FILES_RIME_CANGJIE3_EXTENSION=(
"cangjie5.cj3ext.dict.yaml"
"cangjie5.custom.yaml"
)
DEPENDENCIES=("git")
exists() { type "$1" >/dev/null 2>&1; }
# dependencies check
for DEP in "${DEPENDENCIES[@]}"; do
if ! exists "$DEP"; then
echo "${RED}${BOLD}$DEP is not installed, aborting...${NORMAL}"
exit 1
fi
done
# Start script
#
mkdir -p rime
for REPO in "${GIT_REPOS[@]}"; do
# Get directory name from REPO URL
DIR=$(echo "$REPO" | rev | cut -f1 -d '/' |rev)
# If directory exists by previous run, delete it
if [ -d "$DIR" ]; then
rm -rf "$DIR"
fi
# https://unix.stackexchange.com/questions/732093/bash-loop-associative-array-with-variable-array-name
# nameref: declare -n
VARNAME="REQUIRED_FILES_$(echo "$DIR" | sed 's/-/_/g' | tr '[:lower:]' '[:upper:]')"
declare -n FILE_ARRAY=$VARNAME
if [ "$VARNAME" = "REQUIRED_FILES_RIME_CANTONESE" ];then
BRANCH="main"
else
BRANCH="master"
fi
mkdir "$DIR"
# cd inside this scope. no longer cd into $DIR when out of scope
(
cd "$DIR" || exit
# https://stackoverflow.com/questions/65524512/how-to-disable-git-message-about-git-initial-branch-name
# disable git init hints
git -c "init.defaultBranch=$BRANCH" init
# enable sparse checkout (not enabling cone mode, meaning exact file match is required)
git config core.sparseCheckout true
# add required filenames to sparse-checkout file to make git pull only pull those files
printf "%s\n" "${FILE_ARRAY[@]}" >.git/info/sparse-checkout
# add remote URL
git remote add origin "$REPO"
# git pull with --depth 1 for quick download
git pull --quiet --depth 1 origin "$BRANCH"
# copy required files into rime directory
cp -n -r -t ../rime "${FILE_ARRAY[@]}"
)
rm -rf "$DIR"
done
cat <<EOF >./rime/default.custom.yaml
# https://github.com/rime/home/wiki/UserData
# 用戶文件夾
# Rime 從「用戶文件夾」讀取用家自訂的配置。
# 輸入法運行時保存的數據如 用戶詞典、安裝信息、選項狀態等也放在這裏。
#
# 小狼毫: 用戶文件夾的默認路徑爲 %APPDATA%\Rime。也可以通過「開始菜單小狼毫輸入法用戶文件夾」打開。
# 鼠鬚管: 用戶文件夾的路徑爲 ~/Library/Rime。也可以通過「系統輸入法菜單鼠鬚管用戶設定…」打開。
# ibus-rime: ~/.config/ibus/rime
# fcitx-rime: ~/.config/fcitx/rime
# fcitx5-rime: ~/.local/share/fcitx5/rime/
patch:
schema_list:
- schema: jyut6ping3 # 粵拼
- schema: cangjie5 # 倉頡五代
- schema: quick5 # 速成
- schema: ms_quick # 微軟速成
- schema: stroke # 五筆畫
EOF
printf "%s\n" \
"" \
"${GREEN}${BOLD}\"rime\" directory is generated.${NORMAL}" \
"" \
"${GREEN}${BOLD}Follow the guide below to place it into the correct location.${NORMAL}" \
"${GREEN}${BOLD}https://github.com/rime/home/wiki/UserData${NORMAL}"