Skip to content

Instantly share code, notes, and snippets.

@tomma5o
Last active January 2, 2023 03:32
Show Gist options
  • Save tomma5o/302be3dc6e2092743e6049570e102a09 to your computer and use it in GitHub Desktop.
Save tomma5o/302be3dc6e2092743e6049570e102a09 to your computer and use it in GitHub Desktop.
This gist is for standard install of the zsh shell and oh-my-zsh configuration with spaceship theme
#!/bin/bash
# For use this script copy&paste this in your terminal:
# bash <(curl -s https://gist.githubusercontent.com/tomma5o/302be3dc6e2092743e6049570e102a09/raw/superShell.bash)
OPTIONS="OSX Debian"
SELECTED="null"
echo Where you want to activate zsh?
select opt in $OPTIONS; do
if [ "$opt" = "OSX" ]; then
SELECTED="OSX"
echo your selection is OSX
break
elif [ "$opt" = "Debian" ]; then
SELECTED="Debian"
echo your selection is Debian
break
else
echo bad option
SELECTED="null"
exit 1
fi
done
ohMyZshInstaller() {
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
set -e
if [ ! -n "$ZSH" ]; then
ZSH=~/.oh-my-zsh
fi
if [ -d "$ZSH" ]; then
printf "${YELLOW}You already have Oh My Zsh installed.${NORMAL}\n"
printf "You'll need to remove $ZSH if you want to re-install.\n"
exit
fi
# Prevent the cloned repository from having insecure permissions. Failing to do
# so causes compinit() calls to fail with "command not found: compdef" errors
# for users with insecure umasks (e.g., "002", allowing group writability). Note
# that this will be ignored under Cygwin by default, as Windows ACLs take
# precedence over umasks except for filesystems mounted with option "noacl".
umask g-w,o-w
printf "${BLUE}Cloning Oh My Zsh...${NORMAL}\n"
hash git >/dev/null 2>&1 || {
echo "Error: git is not installed"
exit 1
}
# The Windows (MSYS) Git is not compatible with normal use on cygwin
if [ "$OSTYPE" = cygwin ]; then
if git --version | grep msysgit > /dev/null; then
echo "Error: Windows/MSYS Git is not supported on Cygwin"
echo "Error: Make sure the Cygwin git package is installed and is first on the path"
exit 1
fi
fi
env git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git $ZSH || {
printf "Error: git clone of oh-my-zsh repo failed\n"
exit 1
}
printf "${BLUE}Looking for an existing zsh config...${NORMAL}\n"
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
printf "${YELLOW}Found ~/.zshrc.${NORMAL} ${GREEN}Backing up to ~/.zshrc.pre-oh-my-zsh${NORMAL}\n";
mv ~/.zshrc ~/.zshrc.pre-oh-my-zsh;
fi
printf "${BLUE}Using the Oh My Zsh template file and adding it to ~/.zshrc${NORMAL}\n"
cp $ZSH/templates/zshrc.zsh-template ~/.zshrc
sed "/^export ZSH=/ c\\
export ZSH=$ZSH
" ~/.zshrc > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
}
if [ $SELECTED = "OSX" ]; then
# check if homebrew is already installed
if which brew &> /dev/null; then
brew install zsh
else
echo "installing homebrew...\nAt the end of the precess i ask you if u want to delete Homebrew ;)"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" || {
printf "Error happened when installing homebrew"
exit 1
}
echo "installing zsh..."
brew install zsh zsh-completions
fi
elif [ $SELECTED = "Debian" ]; then
sudo apt-get install zsh
fi
#########################################
# install oh my zsh
#########################################
echo "installing Oh-My-Zsh..."
ohMyZshInstaller
#########################################
# install plugin zsh-autosuggestions
#########################################
echo "installing zsh-autosuggestions..."
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/plugins/zsh-autosuggestions || {
printf "Error happened when installing zsh-autosuggestions"
exit 1
}
#########################################
# install zsh plugin syntax-highlighting
#########################################
echo "installing zsh-syntax-highlighting..."
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git || {
printf "Error happened when installing zsh-autosuggestions"
exit 1
}
#########################################
# install spaceship theme
#########################################
echo "installing spaceship theme..."
git clone https://github.com/denysdovhan/spaceship-prompt.git ~/.oh-my-zsh/themes/spaceship-prompt || {
printf "Error happened when installing spaceship theme"
exit 1
}
ln -s ~/.oh-my-zsh/themes/spaceship-prompt/spaceship.zsh-theme ~/.oh-my-zsh/themes/spaceship.zsh-theme || {
printf "Error happened when installing spaceship theme"
exit 1
}
# @TODO sobstitute ZSH_THEME theme variable with spaceship in .zshrc
if [ $SELECTED = "OSX" ]; then
echo "You want maintain homebrew in your mac? (y/n)"
read YESNO
if [ $YESNO = "y" ]; then
echo "perfect! you find homebrew here: /usr/local/Homebrew"
else
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" || {
echo "Error happened when i'm tryng to uninstall homebrew"
}
fi
unset YESNO
fi
echo "You want zsh be your standard shell? (y/n)"
read YESNO
if [ $YESNO = "y" ]; then
chsh -s /bin/zsh || {
echo "Error happened when i'm tryng to set zsh your default shell"
}
else
echo "okidoki for use zsh type zsh in your shell"
fi
unset YESNO
echo "the only thing to do now is to go in '.zshrc' and change ZSH_THEME variable in 'spaceship' and add to plugins zsh-autosuggestions ;)"
env zsh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment