zsh-shell-init/install-alias.sh
2023-10-10 11:25:43 +08:00

39 lines
1.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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
case "$_continue" in
y | Y) # 如果输入 y 或 Y则用 sed 命令删除 source $alias_init_file 这一行
awk '!/source "$alias_init_file"/' "$rc_file" > tmpfile \
&& mv tmpfile "$rc_file"
echo "##### 覆盖 source $alias_init_file ######"
;;
*)
echo "##### 退出安装 #####"
exit 3
;;
esac
fi
echo "##### 安装 alias.d 正在自动配置环境变量... #####"
}
_install() {
rsync -a --backup --suffix=.bak ./alias.d "$HOME/"
echo "" >> "$rc_file"
echo "source $alias_init_file" >> "$rc_file"
echo "###### install success, enjoy it! #####"
source "$alias_init_file"
}
_check
_install