2019-01-09 10:25:29 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This script installs the default things for having a stylish zsh
|
|
|
|
user_shell=`getent passwd $USER | cut -f7 -d:`
|
|
|
|
|
|
|
|
echo_green() {
|
|
|
|
echo -e '\033[32;1m'$@'\033[0m'
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_green_n() {
|
|
|
|
echo -en '\033[32;1m'$@'\033[0m'
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_yellow() {
|
|
|
|
echo -e '\033[33;1m'$@'\033[0m'
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_yellow_n() {
|
|
|
|
echo -en '\033[33;1m'$@'\033[0m'
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_red() {
|
|
|
|
echo -e '\033[31;1m'$@'\033[0m'
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_red_n() {
|
|
|
|
echo -en '\033[31;1m'$@'\033[0m'
|
|
|
|
}
|
|
|
|
|
|
|
|
test_command() {
|
|
|
|
command -v $1 > /dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
yes_no_ask_required() {
|
|
|
|
yes_no_ask $@
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo_green "Can't continue"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-09 10:25:29 +00:00
|
|
|
yes_no_ask() {
|
|
|
|
echo_green_n $1 "[Y/n]"
|
|
|
|
read -n 1 answer
|
2019-01-09 10:43:34 +00:00
|
|
|
echo_green '\b '
|
|
|
|
if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install() {
|
|
|
|
test_command apt
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo apt install $1
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
test_command pacman
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo pacman -S $1
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Distribution not recognized, can't install $1."
|
|
|
|
}
|
|
|
|
|
|
|
|
git_clone() {
|
|
|
|
echo_green_n "Cloning $1..."
|
|
|
|
git clone $1 $2 > /dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo_green " OK!"
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
configure_zsh() {
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
yes_no_ask "Do you wish to install and configure zsh ?"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo_green "Stopping"
|
|
|
|
return
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
test_command -v git
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
yes_no_ask_required "You'll need git for this, do you wish to install git ?"
|
|
|
|
install git
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
test_command -v zsh
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
yes_no_ask_required echo_green "This magnificent prompt is based on zsh, do you wish to install zsh ?"
|
|
|
|
install zsh
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
mkdir -p $home/.config
|
|
|
|
if [ ! -d $home/.config/oh-my-zsh ]; then
|
|
|
|
git_clone https://github.com/robbyrussell/oh-my-zsh/ $home/.config/oh-my-zsh
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ ! -d $home/.config/dotfiles ]; then
|
|
|
|
git_clone https://gitea.tforgione.fr/tforgione/dotfiles/ $home/.config/dotfiles
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ ! -d $home/.scripts ]; then
|
|
|
|
yes_no_ask "You don't have tforgione's scripts, do you want them ?"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
git_clone https://gitea.tforgione.fr/tforgione/scripts $home/.scripts
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ -f $home/.zshrc ]; then
|
|
|
|
path1=`realpath $home/.zshrc`
|
|
|
|
path2=`realpath $home/.config/dotfiles/zshrc`
|
|
|
|
if [ "$path1" == "$path2" ]; then
|
|
|
|
echo_green "It seems that your zshrc is already a good link."
|
|
|
|
else
|
|
|
|
if `realpath $home/.zshrc`; then
|
|
|
|
echo_green Warning: you already have a zshrc, it will be moved to ~/.zshrc.bak
|
|
|
|
mv $home/.zshrc $home/.zshrc.bak
|
|
|
|
fi
|
|
|
|
echo_green Linking zshrc
|
|
|
|
ln -s $home/.config/dotfiles/zshrc $home/.zshrc
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo_green Linking zshrc
|
|
|
|
ln -s $home/.config/dotfiles/zshrc $home/.zshrc
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ "$user_shell" == "/bin/zsh" ]; then
|
|
|
|
echo_green "It seems that you already use zsh."
|
2019-01-09 10:25:29 +00:00
|
|
|
else
|
2019-01-09 10:43:34 +00:00
|
|
|
echo_green "It seems your shell is not zsh..."
|
|
|
|
yes_no_ask "Do you want to change your shell ? (you'll need root) ?"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo_green "Changing your shell"
|
|
|
|
sudo chsh $user -s /bin/zsh
|
|
|
|
else
|
|
|
|
echo_green "Not doing anything"
|
|
|
|
fi
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
main() {
|
|
|
|
|
|
|
|
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
|
|
|
|
configure_zsh
|
|
|
|
}
|
|
|
|
|
|
|
|
main < /dev/tty
|
2019-01-09 10:25:29 +00:00
|
|
|
|