diff --git a/Makefile b/Makefile index 986ec52..5da628b 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ AS=./install-alias.sh - OS=./install-oh-my-zsh.sh +SHELL=env zsh install: @@ -10,4 +10,6 @@ ohm: chmod +x $(OS) $(OS) -alias: chmod +x $(AS) && $(AS) \ No newline at end of file +alias: + chmod +x $(AS) + $(SHELL) $(AS) \ No newline at end of file diff --git a/install-alias.sh b/install-alias.sh old mode 100644 new mode 100755 index 15847d1..5e9df41 --- a/install-alias.sh +++ b/install-alias.sh @@ -1,45 +1,36 @@ # shellcheck shell=ksh +rc_file="$HOME/.zshrc" +alias_init_file="$HOME/alias.d/.init" -AHome="$HOME/alias.d" -if [ ! -f "$AHome" ];then -echo "将创建 ~/.alias.d 用于存放自定义快捷方式" +# if rc_file contains "sourece $alias_init_file" 询问是否覆盖 -mkdir "$AHome" -fi +_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 -init_shell="$AHome/.init" -echo alias in "$AHome" -echo "" > "$init_shell" + echo "安装 alias.d 正在自动配置环境变量... source $alias_init_file" +} -echo '# set PATH so it includes user`s private bin if it exists' >> "$init_shell" -echo 'if [ -d "$HOME/bin" ] ; then' >> "$init_shell" -echo ' PATH="$HOME/bin:$PATH"' >> "$init_shell" -echo 'fi' >> "$init_shell" -echo '' >> "$init_shell" -echo '# set PATH so it includes user`s private bin if it exists' >> "$init_shell" -echo 'if [ -d "$HOME/.local/bin" ] ; then' >> "$init_shell" -echo ' PATH="$HOME/.local/bin:$PATH"' >> "$init_shell" -echo 'fi' >> "$init_shell" -echo '' >> "$init_shell" -echo '# set PATH so it includes user`s private bin if it exists' >> "$init_shell" -echo 'if [ -d "$HOME/go/bin" ] ; then' >> "$init_shell" -echo ' PATH="$HOME/go/bin:$PATH"' >> "$init_shell" -echo 'fi' >> "$init_shell" -echo "setopt no_nomatch" >> "$init_shell" +_install() { + rsync -a --backup --suffix=.bak ./alias.d "$HOME/" + echo "install success, enjoy it!" + source "$alias_init_file" +} -echo '# 遍历' >> "$init_shell" -echo '# for item in `ls ~/.alias.d/*.sh`; do' >> "$init_shell" -echo '# source $item' >> "$init_shell" -echo '# done' >> "$init_shell" -echo 'export AHome="$HOME"/.alias.d' >> "$init_shell" -echo 'for ali in "$AHome"/*.sh' >> "$init_shell" -echo 'do' >> "$init_shell" -echo ' [[ -e "$ali" ]] || break # 无 alias 停止' >> "$init_shell" -echo ' source "$ali"' >> "$init_shell" -echo 'done' >> "$init_shell" - -echo "#common config" >> "$init_shell" -echo "alias va='vim ~/.alias.d'" >> "$init_shell" -echo "alias vz='vim ~/.zshrc'" >> "$init_shell" -echo "alias rez='source ~/.zshrc'" >> "$init_shell" -echo "source "$init_shell"" >> ~/.zshrc \ No newline at end of file +_check +_install \ No newline at end of file