config zsh

This commit is contained in:
2025-04-21 16:39:45 +08:00
parent 595ce5e8bb
commit 2b08d06733
6 changed files with 2014 additions and 51 deletions

View File

@@ -1,56 +1,21 @@
#!/bin/bash
# Configure ZSH
if [ ! -d $HOME/.oh-my-zsh ]; then
git clone https://github.com/ohmyzsh/ohmyzsh.git $HOME/.oh-my-zsh
fi
current_dir=$(dirname "$0")
if [ ! -d $HOME/.oh-my-zsh/plugins/zsh-autosuggestions ]; then
git clone https://github.com/zsh-users/zsh-autosuggestions.git $HOME/.oh-my-zsh/plugins/zsh-autosuggestions
fi
if [ ! -d $HOME/.oh-my-zsh/plugins/zsh-syntax-highlighting ]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.oh-my-zsh/plugins/zsh-syntax-highlighting
fi
if [ ! -d $HOME/.oh-my-zsh/plugins/zsh-autocomplete ]; then
git clone https://github.com/marlonrichert/zsh-autocomplete.git $HOME/.oh-my-zsh/plugins/zsh-autocomplete
fi
if [ -f $HOME/.zshrc ]; then
if [ ! -f $HOME/.zshrc.bkp ]; then
mv $HOME/.zshrc $HOME/.zshrc.bkp
if [ "$1" = "zsh" ]; then
if [ $# -gt 1 ]; then
for i in "${@:2}"; do
if [ "$i" = "install" ]; then
echo "Installing Oh My Zsh..."
zsh "$current_dir/zsh/install_ohmyzsh.sh"
elif [ "$i" = "config" ]; then
echo "Config Oh My Zsh..."
zsh "$current_dir/zsh/config_ohmyzsh.sh"
elif [ "$i" = "p10k" ]; then
echo "Config Powerlevel10k..."
zsh "$current_dir/zsh/config_p10k.sh"
fi
done
fi
echo "Run \"exec zsh\" to apply changes."
fi
cp $HOME/.oh-my-zsh/templates/zshrc.zsh-template $HOME/.zshrc
zsh_theme_line_num=$(grep -rn -m 1 ZSH_THEME= $HOME/.zshrc | cut -d ":" -f 1)
sed -i $zsh_theme_line_num"c"\ZSH_THEME=\"polyjuice\" $HOME/.zshrc
zsh_plugin_line_number=$(grep -rn -m 2 plugins=\(git\) $HOME/.zshrc | cut -d : -f 1)
sed -i "$zsh_plugin_line_number"c"\plugins=\(zsh-autosuggestions zsh-syntax-highlighting zsh-autocomplete\)" $HOME/.zshrc
if [ -f $HOME/.oh-my-zsh/themes/polyjuice.zsh-theme ]; then
rm -rf $HOME/.oh-my-zsh/themes/polyjuice.zsh-theme
fi
path_to_theme=$(realpath $0 | sed 's/\.sh/\.zsh-theme/')
ln -i -s $path_to_theme $HOME/.oh-my-zsh/themes/polyjuice.zsh-theme
# Configure the software folder: $HOME/.software
if [ ! -d $HOME/.software ]; then
mkdir $HOME/.software
fi
if [ ! -f $HOME/.software/software_env.sh ]; then
touch $HOME/.software/software_env.sh
fi
# if [ ! -f $HOME/.zshenv ]; then
# touch $HOME/.zshenv
# fi
# nl $HOME/.zshenv | grep \.software/software_env\.sh > /dev/null
# if [ ! $? == 0 ]; then
# echo ". $HOME/.software/software_env.sh" >> $HOME/.zshenv
# fi