This commit is contained in:
Thomas Forgione 2019-04-15 17:19:59 +02:00
parent 1b2b84ea27
commit 81a47b3dad
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 48 additions and 41 deletions

View File

@ -1,47 +1,51 @@
#!/usr/bin/env bash #!/usr/bin/env sh
# This script installs the default things for having a stylish zsh # This script installs the default things for having a stylish zsh
user_shell=`getent passwd $USER | cut -f7 -d:` user_shell=`getent passwd $USER | cut -f7 -d:`
info() {
echo -e '\033[1m'info:'\033[0m' $@
}
info_n() {
echo -en '\033[1m'info:'\033[0m' $@
}
warn() {
echo -e '\033[33;1m'warning:'\033[0m' $@
}
warn_n() {
echo -en '\033[33;1m'warning:'\033[0m' $@
}
error() {
echo -e '\033[31;1m'error:'\033[0m' $@
}
error_n() {
echo -en '\033[31;1m'error:'\033[0m' $@
}
echo_green() { echo_green() {
echo -e '\033[32;1m'$@'\033[0m' 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() { test_command() {
command -v $1 > /dev/null 2>&1 command -v $1 > /dev/null 2>&1
} }
yes_no_ask_required() { yes_no_ask_required() {
yes_no_ask $@ yes_no_ask $@ "(required)"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo_green "Can't continue" error "can't continue"
exit 1 exit 1
fi fi
} }
yes_no_ask() { yes_no_ask() {
echo_green_n $1 "[Y/n]" info_n $@ "[Y/n]"
read -n answer read answer
if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
return 0 return 0
else else
@ -62,34 +66,37 @@ install() {
return return
fi fi
echo_red "Distribution not recognized, can't install $1." error "distribution not recognized, can't install $1."
} }
git_clone() { git_clone() {
echo_green_n "Cloning $1..." info_n "Cloning $1..."
git clone $1 $2 > /dev/null 2>&1 git clone $1 $2 > /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo_green " OK!" echo " OK!"
else
echo
error "clone failed!"
fi fi
} }
configure_zsh() { configure_zsh() {
yes_no_ask "Do you wish to install and configure zsh ?" yes_no_ask "do you wish to install and configure zsh ?"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo_green "Stopping" info "exiting"
return return
fi fi
test_command -v git test_command -v git
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
yes_no_ask_required "You'll need git for this, do you wish to install git ?" yes_no_ask_required "you'll need git for this, do you wish to install git ?"
install git install git
fi fi
test_command -v zsh test_command -v zsh
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
yes_no_ask_required echo_green "This magnificent prompt is based on zsh, do you wish to install zsh ?" yes_no_ask_required "this magnificent prompt is based on zsh, do you wish to install zsh ?"
install zsh install zsh
fi fi
@ -106,30 +113,30 @@ configure_zsh() {
path1=`realpath $HOME/.zshrc` path1=`realpath $HOME/.zshrc`
path2=`realpath $HOME/.config/dotfiles/zshrc` path2=`realpath $HOME/.config/dotfiles/zshrc`
if [ "$path1" == "$path2" ]; then if [ "$path1" == "$path2" ]; then
echo_green "It seems that your zshrc is already a good link." info "it seems that your zshrc is already a good link."
else else
if `realpath $HOME/.zshrc`; then if `realpath $HOME/.zshrc`; then
echo_green Warning: you already have a zshrc, it will be moved to ~/.zshrc.bak warn "you already have a zshrc, it will be moved to ~/.zshrc.bak"
mv $HOME/.zshrc $HOME/.zshrc.bak mv $HOME/.zshrc $HOME/.zshrc.bak
fi fi
echo_green Linking zshrc info "linking zshrc"
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
fi fi
else else
echo_green Linking zshrc info "linking zshrc"
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
fi fi
if [ "$user_shell" == "/bin/zsh" ]; then if [ "$user_shell" == "/bin/zsh" ]; then
echo_green "It seems that you already use zsh." info "it seems that you already use zsh."
else else
echo_green "It seems your shell is not zsh..." info "it seems your shell is not zsh..."
yes_no_ask "Do you want to change your shell ? (you'll need root) ?" yes_no_ask "do you want to change your shell ? (you'll need root) ?"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo_green "Changing your shell" info "changing your shell"
sudo chsh $user -s /bin/zsh sudo chsh $user -s /bin/zsh
else else
echo_green "Not doing anything" info "not doing anything"
fi fi
fi fi
} }