2023-09-07 19:28:32 +08:00
|
|
|
|
# shellcheck shell=ksh
|
2023-09-13 16:56:40 +08:00
|
|
|
|
rc_file="$HOME/.zshrc"
|
|
|
|
|
alias_init_file="$HOME/alias.d/.init"
|
2023-09-07 19:28:32 +08:00
|
|
|
|
|
2023-09-13 16:56:40 +08:00
|
|
|
|
# if rc_file contains "sourece $alias_init_file" 询问是否覆盖
|
2023-09-07 19:28:32 +08:00
|
|
|
|
|
2023-09-13 16:56:40 +08:00
|
|
|
|
_check() {
|
|
|
|
|
if grep -q "source $alias_init_file" "$rc_file"; then
|
|
|
|
|
# 如果包含,则询问是否覆盖
|
|
|
|
|
echo "看起来设备已经安装 alias, $rc_file 中包含 source $alias_init_file"
|
|
|
|
|
echo -n "请输入(y/n):"
|
|
|
|
|
read -r _continue
|
2023-09-13 17:10:07 +08:00
|
|
|
|
|
2023-09-13 16:56:40 +08:00
|
|
|
|
case "$_continue" in
|
|
|
|
|
y | Y) # 如果输入 y 或 Y,则用 sed 命令删除 source $alias_init_file 这一行
|
2023-09-13 17:10:07 +08:00
|
|
|
|
awk '!/source "$alias_init_file"/' "$rc_file" > tmpfile && mv tmpfile "$rc_file"
|
|
|
|
|
echo "##### 覆盖 source $alias_init_file ######"
|
2023-09-13 16:56:40 +08:00
|
|
|
|
;;
|
|
|
|
|
*)
|
2023-09-13 17:10:07 +08:00
|
|
|
|
echo "##### 退出安装 #####"
|
2023-09-13 16:56:40 +08:00
|
|
|
|
exit 3
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
fi
|
2023-09-07 19:28:32 +08:00
|
|
|
|
|
2023-09-13 17:10:07 +08:00
|
|
|
|
echo "##### 安装 alias.d 正在自动配置环境变量... #####"
|
2023-09-13 16:56:40 +08:00
|
|
|
|
}
|
2023-09-07 19:28:32 +08:00
|
|
|
|
|
2023-09-13 16:56:40 +08:00
|
|
|
|
_install() {
|
|
|
|
|
rsync -a --backup --suffix=.bak ./alias.d "$HOME/"
|
2023-09-13 17:10:07 +08:00
|
|
|
|
echo "###### install success, enjoy it! #####"
|
2023-09-13 16:56:40 +08:00
|
|
|
|
source "$alias_init_file"
|
|
|
|
|
}
|
2023-09-07 19:28:32 +08:00
|
|
|
|
|
2023-09-13 16:56:40 +08:00
|
|
|
|
_check
|
|
|
|
|
_install
|