diff --git a/zsh/check.sh b/zsh/functions/check.sh similarity index 100% rename from zsh/check.sh rename to zsh/functions/check.sh diff --git a/zsh/config_starship.sh b/zsh/functions/config_starship.sh similarity index 100% rename from zsh/config_starship.sh rename to zsh/functions/config_starship.sh diff --git a/zsh/functions/install.sh b/zsh/functions/install.sh new file mode 100644 index 0000000..81b3e4c --- /dev/null +++ b/zsh/functions/install.sh @@ -0,0 +1,103 @@ +#! /bin/bash + +echo "$SHELL" | grep -q zsh +if [ $? -ne 0 ]; then + echo "Please run this script in zsh shell." + exit 1 +fi + +# git, fzf, zoxide are required +if ! command -v git >/dev/null 2>&1; then + echo "Git is not installed." + exit 1 +fi + +if ! command -v fzf >/dev/null 2>&1; then + echo "FZF is not installed." + exit 1 +fi + +if ! command -v zoxide >/dev/null 2>&1; then + echo "Zoxide is not installed." + exit 1 +fi + +if ! command -v python >/dev/null 2>&1; then + if ! command -v python3 >/dev/null 2>&1; then + echo "Python is not installed." + exit 1 + fi +fi + +if ! command -v starship >/dev/null 2>&1; then + echo "Starship is not installed." + exit 1 +fi + +ZSH_POLYJUICE_PATH="$HOME/.TerminalPolyjuice" +PLUGINS_PATH="$ZSH_POLYJUICE_PATH/zsh/plugins" + +# git clone zsh-autosuggestions +if [ ! -d "$PLUGINS_PATH"/zsh-autosuggestions ]; then + echo "Zsh Autosuggestions is not downloaded. Downloading..." + # git clone https://github.com/zsh-users/zsh-autosuggestions.git "$PLUGINS_PATH"/zsh-autosuggestions + git clone https://gitee.com/mirrors/zsh-autosuggestions.git "$PLUGINS_PATH"/zsh-autosuggestions +else + cd "$PLUGINS_PATH"/zsh-autosuggestions || exit 1 + if [ ! -d .git ]; then + echo "Zsh Autosuggestions is not a git repository. Please remove $PLUGINS_PATH/zsh-autosuggestions and try again." + exit 1 + else + echo "Zsh Autosuggestions is already exist. Updating..." + git pull + fi +fi + +# git clone zsh-syntax-highlighting +if [ ! -d "$PLUGINS_PATH"/zsh-syntax-highlighting ]; then + echo "Zsh Syntax Highlighting is not downloaded. Downloading..." + # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$PLUGINS_PATH"/zsh-syntax-highlighting + git clone https://gitee.com/mirrors/zsh-syntax-highlighting.git "$PLUGINS_PATH"/zsh-syntax-highlighting +else + cd "$PLUGINS_PATH"/zsh-syntax-highlighting || exit 1 + if [ ! -d .git ]; then + echo "Zsh Syntax Highlighting is not a git repository. Please remove $PLUGINS_PATH/zsh-syntax-highlighting and try again." + exit 1 + else + echo "Zsh Syntax Highlighting is already exist. Updating..." + git pull + fi +fi + +# git clone zsh-autocomplete +if [ ! -d "$PLUGINS_PATH"/zsh-autocomplete ]; then + echo "Zsh Autocomplete is not downloaded. Downloading..." + # git clone https://github.com/marlonrichert/zsh-autocomplete.git "$PLUGINS_PATH"/zsh-autocomplete + git clone https://gitee.com/mirrors/zsh-autocomplete.git "$PLUGINS_PATH"/zsh-autocomplete + +else + cd "$PLUGINS_PATH"/zsh-autocomplete || exit 1 + if [ ! -d .git ]; then + echo "Zsh Autocomplete is not a git repository. Please remove $PLUGINS_PATH/zsh-autocomplete and try again." + exit 1 + else + echo "Zsh Autocomplete is already exist. Updating..." + git pull + fi +fi + +# git clone powerlevel10k +if [ ! -d "$PLUGINS_PATH"/fzf-tab ]; then + echo "fzf-tab is not downloaded. Downloading..." + git clone https://github.com/Aloxaf/fzf-tab.git "$PLUGINS_PATH"/fzf-tab +else + cd "$PLUGINS_PATH/fzf-tab" || exit 1 + if [ ! -d .git ]; then + echo "fzf-tab is not a git repository. Please remove $PLUGINS_PATH/fzf-tab and try again." + exit 1 + else + echo "fzf-tab is already exist. Updating..." + git pull + fi +fi + diff --git a/zsh/install_ohmyzsh.sh b/zsh/install_ohmyzsh.sh deleted file mode 100644 index a670436..0000000 --- a/zsh/install_ohmyzsh.sh +++ /dev/null @@ -1,143 +0,0 @@ -#! /bin/bash - -echo "$SHELL" | grep -q zsh -if [ $? -ne 0 ]; then - echo "Please run this script in zsh shell." - exit 1 -fi - -# git, fzf, zoxide are required -if ! command -v git >/dev/null 2>&1; then - echo "Git is not installed." - exit 1 -fi - -if ! command -v fzf >/dev/null 2>&1; then - echo "FZF is not installed." - exit 1 -fi - -if ! command -v zoxide >/dev/null 2>&1; then - echo "Zoxide is not installed." - exit 1 -fi - -if ! command -v python >/dev/null 2>&1; then - if ! command -v python3 >/dev/null 2>&1; then - echo "Python is not installed." - exit 1 - fi -fi - -if ! command -v starship >/dev/null 2>&1; then - echo "Starship is not installed." - exit 1 -fi - -# Path -PATH_OHMYZSH="$HOME/.oh-my-zsh" -PATH_OHMYZSH_CUSTOM_PLUGINS="$PATH_OHMYZSH/custom/plugins" -PATH_OHMYZSH_CUSTOM_THEMES="$PATH_OHMYZSH/custom/themes" - -# git clone oh-my-zsh -if [ ! -d "$PATH_OHMYZSH" ]; then - echo "Oh My Zsh is not downloaded. Downloading..." - # git clone https://github.com/ohmyzsh/ohmyzsh.git "$PATH_OHMYZSH" - git clone https://gitee.com/mirrors/ohmyzsh.git "$PATH_OHMYZSH" -else - cd "$PATH_OHMYZSH" || exit 2 - if [ ! -d .git ]; then - echo "Oh My Zsh is not a git repository. Please remove $PATH_OHMYZSH and try again." - exit 1 - else - echo "Oh My Zsh is already exist. Updating..." - git pull - fi -fi - -# git clone zsh-autosuggestions -if [ ! -d "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autosuggestions ]; then - echo "Zsh Autosuggestions is not downloaded. Downloading..." - # git clone https://github.com/zsh-users/zsh-autosuggestions.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autosuggestions - git clone https://gitee.com/mirrors/zsh-autosuggestions.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autosuggestions -else - cd "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autosuggestions || exit 1 - if [ ! -d .git ]; then - echo "Zsh Autosuggestions is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_PLUGINS/zsh-autosuggestions and try again." - exit 1 - else - echo "Zsh Autosuggestions is already exist. Updating..." - git pull - fi -fi - -# git clone zsh-syntax-highlighting -if [ ! -d "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-syntax-highlighting ]; then - echo "Zsh Syntax Highlighting is not downloaded. Downloading..." - # git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-syntax-highlighting - git clone https://gitee.com/mirrors/zsh-syntax-highlighting.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-syntax-highlighting -else - cd "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-syntax-highlighting || exit 1 - if [ ! -d .git ]; then - echo "Zsh Syntax Highlighting is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_PLUGINS/zsh-syntax-highlighting and try again." - exit 1 - else - echo "Zsh Syntax Highlighting is already exist. Updating..." - git pull - fi -fi - -# git clone zsh-autocomplete -if [ ! -d "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autocomplete ]; then - echo "Zsh Autocomplete is not downloaded. Downloading..." - # git clone https://github.com/marlonrichert/zsh-autocomplete.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autocomplete - git clone https://gitee.com/mirrors/zsh-autocomplete.git "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autocomplete - -else - cd "$PATH_OHMYZSH_CUSTOM_PLUGINS"/zsh-autocomplete || exit 1 - if [ ! -d .git ]; then - echo "Zsh Autocomplete is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_PLUGINS/zsh-autocomplete and try again." - exit 1 - else - echo "Zsh Autocomplete is already exist. Updating..." - git pull - fi -fi - -# git clone powerlevel10k -# if [ ! -d "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k ]; then -# echo "Powerlevel10k is not downloaded. Downloading..." -# # git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k -# git clone --depth=1 https://gitee.com/gwbeip/powerlevel10k.git "$PATH_OHMYZSH_CUSTOM_THEMES"/powerlevel10k -# else -# cd "$PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k" || exit 1 -# if [ ! -d .git ]; then -# echo "Zsh Autocomplete is not a git repository. Please remove $PATH_OHMYZSH_CUSTOM_THEMES/powerlevel10k and try again." -# exit 1 -# else -# echo "Powerlevel10k is already exist. Updating..." -# git pull -# fi -# fi - - -# copying $HOME/.zshrc -current_dir=$(dirname $(realpath "$0")) - -if [ -f "$HOME/.zshrc" ]; then - if $(file "$HOME/.zshrc" | grep -q "symbolic link") ; then - if [[ $(readlink "$HOME/.zshrc") != "$current_dir/zshrc" ]]; then - ln -sf "$current_dir/zshrc" "$HOME/.zshrc" - fi - else - if [ ! -f "$HOME/.zshrc.bkp" ]; then - mv "$HOME/.zshrc" "$HOME/.zshrc.bkp" - ln -s "$current_dir/zshrc" "$HOME/.zshrc" - else - echo "Backup file already exists. Please remove $HOME/.zshrc.bkp and try again." - exit 1 - fi - fi -else - ln -s "$current_dir/zshrc" "$HOME/.zshrc" -fi diff --git a/zsh/polyjuice.sh b/zsh/polyjuice.sh index e47176f..314a078 100644 --- a/zsh/polyjuice.sh +++ b/zsh/polyjuice.sh @@ -13,28 +13,50 @@ else fi for i in "$@"; do - if [ "$i" = "install_ohmyzsh" ]; then - echo "Installing Oh My Zsh..." - zsh "$current_dir/install_ohmyzsh.sh" + if [ "$i" = "install" ]; then + echo "Installing related software..." + zsh "$current_dir/function/install.sh" if [ $? -ne 0 ]; then - echo "Oh My Zsh installation failed." + echo "related software installation failed." exit 1 fi elif [ "$i" = "config_starship" ]; then echo "Config Starship..." - zsh "$current_dir/config_starship.sh" + zsh "$current_dir/function/config_starship.sh" if [ $? -ne 0 ]; then echo "Starship configuration failed." exit 1 fi elif [ "$i" = "check" ]; then - echo "chcking uninstalled software..." - zsh "$current_dir/check.sh" + echo "Checking uninstalled software..." + zsh "$current_dir/function/check.sh" if [ $? -ne 0 ]; then echo "Check failed." exit 1 fi fi done + +# copying $HOME/.zshrc +current_dir=$(dirname $(realpath "$0")) + +if [ -f "$HOME/.zshrc" ]; then + if $(file "$HOME/.zshrc" | grep -q "symbolic link") ; then + if [[ $(readlink "$HOME/.zshrc") != "$current_dir/zshrc" ]]; then + ln -sf "$current_dir/zshrc" "$HOME/.zshrc" + fi + else + if [ ! -f "$HOME/.zshrc.bkp" ]; then + mv "$HOME/.zshrc" "$HOME/.zshrc.bkp" + ln -s "$current_dir/zshrc" "$HOME/.zshrc" + else + echo "Backup file already exists. Please remove $HOME/.zshrc.bkp and try again." + exit 1 + fi + fi +else + ln -s "$current_dir/zshrc" "$HOME/.zshrc" +fi + echo "Run \"exec zsh\" to apply changes." # exec zsh \ No newline at end of file diff --git a/zsh/zshrc b/zsh/zshrc index c4cdab7..639a751 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -18,6 +18,9 @@ setopt hist_reduce_blanks # 合并连续的空命令 # setopt hist_find_no_dups # 搜索历史时忽略重复项 # setopt hist_save_no_dups # 保存历史时忽略重复项 +# Load Aliases +source $ZSH_ALIAS_PATH/alias.sh + # Load Plugins source $ZSH_PLUGIN_PATH/zsh-autosuggestions/zsh-autosuggestions.zsh ZSH_AUTOSUGGEST_STRATEGY=(history completion) @@ -25,15 +28,13 @@ ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20 bindkey '^[l' autosuggest-accept # alt-L to accept autosuggestion source $ZSH_PLUGIN_PATH/zsh-autocomplete/zsh-autocomplete.plugin.zsh source $ZSH_PLUGIN_PATH/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh - -# Load Aliases -source $ZSH_ALIAS_PATH/alias.sh +source $ZSH_PLUGIN_PATH/fzf-tab/fzf-tab.plugin.zsh # zoxide if (( $+commands[zoxide] )); then eval "$(zoxide init --cmd ${ZOXIDE_CMD_OVERRIDE:-z} zsh)" else - echo '[oh-my-zsh] zoxide not found, please install it from https://github.com/ajeetdsouza/zoxide' + echo '[zoxide] not found, please install it from https://github.com/ajeetdsouza/zoxide' fi # You may need to manually set your language environment