installer: extract most code into functions
This commit is contained in:
parent
ebd3bf82c0
commit
d5bb072375
@ -43,22 +43,7 @@ setup_color() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
setup_ohmyzsh() {
|
||||||
setup_color
|
|
||||||
|
|
||||||
if ! command_exists zsh; then
|
|
||||||
echo "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -d "$ZSH" ]; then
|
|
||||||
cat <<-EOF
|
|
||||||
${YELLOW}You already have Oh My Zsh installed.${NORMAL}
|
|
||||||
You'll need to remove $ZSH if you want to re-install.
|
|
||||||
EOF
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Prevent the cloned repository from having insecure permissions. Failing to do
|
# Prevent the cloned repository from having insecure permissions. Failing to do
|
||||||
# so causes compinit() calls to fail with "command not found: compdef" errors
|
# so causes compinit() calls to fail with "command not found: compdef" errors
|
||||||
# for users with insecure umasks (e.g., "002", allowing group writability). Note
|
# for users with insecure umasks (e.g., "002", allowing group writability). Note
|
||||||
@ -85,11 +70,13 @@ main() {
|
|||||||
echo "Error: git clone of oh-my-zsh repo failed"
|
echo "Error: git clone of oh-my-zsh repo failed"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_zshrc() {
|
||||||
echo "${BLUE}Looking for an existing zsh config...${NORMAL}"
|
echo "${BLUE}Looking for an existing zsh config...${NORMAL}"
|
||||||
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
|
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
|
||||||
echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${NORMAL}"
|
echo "${YELLOW}Found ~/.zshrc.${GREEN} Backing up to ~/.zshrc.pre-oh-my-zsh.${NORMAL}"
|
||||||
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
|
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${NORMAL}"
|
echo "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc.${NORMAL}"
|
||||||
@ -100,6 +87,7 @@ main() {
|
|||||||
" ~/.zshrc > ~/.zshrc-omztemp
|
" ~/.zshrc > ~/.zshrc-omztemp
|
||||||
mv -f ~/.zshrc-omztemp ~/.zshrc
|
mv -f ~/.zshrc-omztemp ~/.zshrc
|
||||||
|
|
||||||
|
setup_shell() {
|
||||||
# If this user's login shell is not already "zsh", attempt to switch.
|
# If this user's login shell is not already "zsh", attempt to switch.
|
||||||
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
|
TEST_CURRENT_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
|
||||||
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
|
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
|
||||||
@ -115,6 +103,29 @@ main() {
|
|||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
setup_color
|
||||||
|
|
||||||
|
if ! command_exists zsh; then
|
||||||
|
echo "${YELLOW}Zsh is not installed!${NORMAL} Please install zsh first!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$ZSH" ]; then
|
||||||
|
cat <<-EOF
|
||||||
|
${YELLOW}You already have Oh My Zsh installed.${NORMAL}
|
||||||
|
You'll need to remove $ZSH if you want to reinstall.
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
setup_ohmyzsh
|
||||||
|
|
||||||
|
setup_zshrc
|
||||||
|
|
||||||
|
setup_shell
|
||||||
|
|
||||||
printf $GREEN
|
printf $GREEN
|
||||||
cat <<-'EOF'
|
cat <<-'EOF'
|
||||||
|
Loading…
Reference in New Issue
Block a user