From 92c378b4c5481825f4f87c02d7d2cf08e67242fc Mon Sep 17 00:00:00 2001 From: xunmi Date: Thu, 25 Jan 2024 15:23:41 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E]=20bash=E9=80=89=E8=A3=85?= =?UTF-8?q?=E6=A8=A1=E5=9D=97,=20=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81,=20=E4=BC=98=E5=8C=96zshrc=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=A2=84=E8=AE=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- start.sh | 61 +++++++++++++++++++++++++++++++++++++----------------- 配置/zshrc | 3 ++- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/start.sh b/start.sh index 685fa23..67db33e 100755 --- a/start.sh +++ b/start.sh @@ -1,10 +1,10 @@ #!/usr/bin/bash # https://gitea.whlug.cn/xunmi/getLinux/src/start.sh - PACK_LIST=("wget" "git" "zsh") +# 脚本根地址 ROOT_URL="https://gitea.whlug.cn/xunmi/getLinux/" -ROOT_TMP=/tmp/xunmi +# 插件和依赖安装的路径 ROOT_INSTALL=/opt/xunmi ############################################################################### @@ -54,14 +54,25 @@ ColorReset() { # 函数 # ############################################################################### +# 选择判断器 +Select_Continue() { + Show 0 "$1((是/否 Yes/No))" + read r + if echo "$r" | grep -Eq "^[是Yy][Ee]?[Ss]?$";then + return 1 + else + return 0 + fi +} + # 更新包管理器 Update_Package_Resource() { Show 2 "更新包管理器..." - GreyStart + GreyStart if [ -x "$(command -v apt)" ]; then - ${sudo_cmd} apt update + sudo apt-get update -qq elif [ -x "$(command -v yum)" ]; then - ${sudo_cmd} yum update + sudo yum update fi ColorReset Show 0 "包管理器更新完毕" @@ -69,10 +80,10 @@ Update_Package_Resource() { # 安装Zsh Install_Zsh() { + Update_Package_Resource for ((i = 0; i < ${#PACK_LIST[@]}; i++)); do pack=${PACK_LIST[i]} Show 2 "安装必要的依赖项: ${aCOLOUR[4]} $pack $COLOUR_RESET" - Update_Package_Resource GreyStart if [ -x "$(command -v apt)" ]; then sudo apt -y install $pack @@ -90,28 +101,40 @@ Install_Zsh() { Show 0 "依赖安装完成" } +# 下载配置 Download_Config() { # 创建下载文件的临时目录 GreyStart - sudo rm -rf -v ${TMP_ROOT} - mkdir -p -v ${TMP_ROOT} || Show 1 "无法创建临时目录" - tmp_dir=$(mktemp -d -p -v ${TMP_ROOT} || Show 1 "无法创建临时目录") - Show 0 "创建临时目录: ${tmp_dir}" + Show 0 "正在进行插件下载与配置" - # 下载配置 - config_url=${ROOT_URL}/src/配置/zshrc - wget -t 3 -q --show-progress -c "${config_url}" || Show 1 "无法下载配置" # 下载zsh扩展 ohmyzsh_dir=${ROOT_INSTALL}/oh-my-zsh - git clone https://gitcode.com/mirrors/ohmyzsh/ohmyzsh.git ${ohmyzsh_dir} - cd -v ${ohmyzsh_dir}/custom/plugins/ - git clone https://gitcode.com/mirrors/zsh-users/zsh-autosuggestions.git - git clone https://gitcode.com/mirrors/zsh-users/zsh-syntax-highlighting.git - sudo cp -v ${tmp_dir}/zshrc /etc/skel/.zshrc - sudo cp -v /etc/skel/.zshrc $HOME + sudo git clone https://gitcode.com/mirrors/ohmyzsh/ohmyzsh.git ${ohmyzsh_dir} + cd ${ohmyzsh_dir}/custom/plugins/ + sudo git clone https://gitcode.com/mirrors/zsh-users/zsh-autosuggestions.git + sudo git clone https://gitcode.com/mirrors/zsh-users/zsh-syntax-highlighting.git + # 下载预设配置 + config_url=${ROOT_URL}/raw/配置/zshrc + sudo wget -t 3 -q --show-progress -c "${config_url}" || Show 1 "无法下载预设配置(${config_url})" + sed -i "s/export ZSH=\/etc\/oh-my-zsh/export ZSH=$ohmyzsh_dir/" zshrc + sudo mv zshrc /etc/skel/.zshrc + cp -v /etc/skel/.zshrc $HOME ColorReset Show 2 "寻觅基础环境安装完成" } +# 选配 +Select_Config(){ + if Select_Continue "启动zsh"; then + zsh + Show 2 "zsh启动完成" + fi + if Select_Continue "将Zsh设置为默认命令行"; then + sudo chsh -s /usr/bin/zsh + Show 2 "已将zsh设置为默认命令行" + fi +} + Install_Zsh Download_Config +Select_Config diff --git a/配置/zshrc b/配置/zshrc index 0e5d522..120cedb 100644 --- a/配置/zshrc +++ b/配置/zshrc @@ -66,7 +66,8 @@ plugins=( zsh-syntax-highlighting ) -source /usr/share/doc/pkgfile/command-not-found.zsh +# arch系列安装pkgfile后可以使用其内置的command-not-found功能 +# source /usr/share/doc/pkgfile/command-not-found.zsh source $ZSH/oh-my-zsh.sh