Work
This commit is contained in:
		
							parent
							
								
									1b2b84ea27
								
							
						
					
					
						commit
						81a47b3dad
					
				
							
								
								
									
										89
									
								
								tforgione.sh
									
									
									
									
									
								
							
							
						
						
									
										89
									
								
								tforgione.sh
									
									
									
									
									
								
							@ -1,47 +1,51 @@
 | 
			
		||||
#!/usr/bin/env bash
 | 
			
		||||
#!/usr/bin/env sh
 | 
			
		||||
 | 
			
		||||
# This script installs the default things for having a stylish zsh
 | 
			
		||||
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 -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
yes_no_ask_required() {
 | 
			
		||||
    yes_no_ask $@
 | 
			
		||||
    yes_no_ask $@ "(required)"
 | 
			
		||||
    if [ $? -ne 0 ]; then
 | 
			
		||||
        echo_green "Can't continue"
 | 
			
		||||
        error "can't continue"
 | 
			
		||||
        exit 1
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
yes_no_ask() {
 | 
			
		||||
    echo_green_n $1 "[Y/n]"
 | 
			
		||||
    read -n answer
 | 
			
		||||
    info_n $@ "[Y/n]"
 | 
			
		||||
    read answer
 | 
			
		||||
    if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
 | 
			
		||||
        return 0
 | 
			
		||||
    else
 | 
			
		||||
@ -62,34 +66,37 @@ install() {
 | 
			
		||||
        return
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    echo_red "Distribution not recognized, can't install $1."
 | 
			
		||||
    error "distribution not recognized, can't install $1."
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
git_clone() {
 | 
			
		||||
    echo_green_n "Cloning $1..."
 | 
			
		||||
    info_n "Cloning $1..."
 | 
			
		||||
    git clone $1 $2 > /dev/null 2>&1
 | 
			
		||||
    if [ $? -eq 0 ]; then
 | 
			
		||||
        echo_green " OK!"
 | 
			
		||||
        echo " OK!"
 | 
			
		||||
    else
 | 
			
		||||
        echo
 | 
			
		||||
        error "clone failed!"
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
        echo_green "Stopping"
 | 
			
		||||
        info "exiting"
 | 
			
		||||
        return
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    test_command -v git
 | 
			
		||||
    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
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    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 ?"
 | 
			
		||||
        yes_no_ask_required "this magnificent prompt is based on zsh, do you wish to install zsh ?"
 | 
			
		||||
        install zsh
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
@ -106,30 +113,30 @@ configure_zsh() {
 | 
			
		||||
        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."
 | 
			
		||||
            info "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
 | 
			
		||||
                warn "you already have a zshrc, it will be moved to ~/.zshrc.bak"
 | 
			
		||||
                mv $HOME/.zshrc $HOME/.zshrc.bak
 | 
			
		||||
            fi
 | 
			
		||||
            echo_green Linking zshrc
 | 
			
		||||
            info "linking zshrc"
 | 
			
		||||
            ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
 | 
			
		||||
        fi
 | 
			
		||||
    else
 | 
			
		||||
        echo_green Linking zshrc
 | 
			
		||||
        info "linking zshrc"
 | 
			
		||||
        ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    if [ "$user_shell" == "/bin/zsh" ]; then
 | 
			
		||||
        echo_green "It seems that you already use zsh."
 | 
			
		||||
        info "it seems that you already use zsh."
 | 
			
		||||
    else
 | 
			
		||||
        echo_green "It seems your shell is not zsh..."
 | 
			
		||||
        yes_no_ask "Do you want to change your shell ? (you'll need root) ?"
 | 
			
		||||
        info "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"
 | 
			
		||||
            info "changing your shell"
 | 
			
		||||
            sudo chsh $user -s /bin/zsh
 | 
			
		||||
        else
 | 
			
		||||
            echo_green "Not doing anything"
 | 
			
		||||
            info "not doing anything"
 | 
			
		||||
        fi
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user