36 lines
963 B
Bash
Executable File
36 lines
963 B
Bash
Executable File
# shellcheck shell=ksh
|
||
rc_file="$HOME/.zshrc"
|
||
alias_init_file="$HOME/alias.d/.init"
|
||
|
||
# if rc_file contains "sourece $alias_init_file" 询问是否覆盖
|
||
|
||
_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
|
||
echo "in >> $_continue"
|
||
case "$_continue" in
|
||
y | Y) # 如果输入 y 或 Y,则用 sed 命令删除 source $alias_init_file 这一行
|
||
sed -i "/source $alias_init_file/d" $rc_file
|
||
echo "覆盖 source $alias_init_file"
|
||
;;
|
||
*)
|
||
echo "退出安装"
|
||
exit 3
|
||
;;
|
||
esac
|
||
fi
|
||
|
||
echo "安装 alias.d 正在自动配置环境变量... source $alias_init_file"
|
||
}
|
||
|
||
_install() {
|
||
rsync -a --backup --suffix=.bak ./alias.d "$HOME/"
|
||
echo "install success, enjoy it!"
|
||
source "$alias_init_file"
|
||
}
|
||
|
||
_check
|
||
_install |