180 lines
3.5 KiB
Bash
180 lines
3.5 KiB
Bash
#!/bin/bash
|
|
cd $(dirname $0)
|
|
|
|
# COLORS
|
|
source ./asides/color.sh
|
|
|
|
KEY_PHRASE="#hugogogo#"
|
|
HERE=$(pwd)
|
|
D_CONFIG_FILES="config_files"
|
|
ASK_INSTALL="y"
|
|
|
|
# create those folders if necessary :
|
|
mkdir -p ~/.vim/templates
|
|
mkdir -p ~/.vim/swapfiles
|
|
|
|
|
|
# receive 1 argument : absolute path to config file
|
|
function save_bak
|
|
{
|
|
local file_to="$1"
|
|
local file_name="$(basename $1)"
|
|
local path_file_to="$(dirname $1)"
|
|
|
|
number=0
|
|
while [ -f $file_to.hubak$number ]
|
|
do
|
|
((number+=1))
|
|
done
|
|
echo -en $YELLOW"in "
|
|
echo -en $CYAN"\"$path_file_to/\""
|
|
echo -en $YELLOW", saving "
|
|
echo -en $CYAN"\"$file_name\""
|
|
echo -en $YELLOW" as "
|
|
echo -en $CYAN"\"$file_name.hubak$number\""$ENDCO"\n"
|
|
mv $file_to $file_to.hubak$number
|
|
}
|
|
|
|
# receives 1 argument : "absolute path to config file"
|
|
function install
|
|
{
|
|
local file_to="$1"
|
|
local file_name="$(basename $1)"
|
|
local path_file_to="$(dirname $1)"
|
|
|
|
local create_sym=1
|
|
|
|
if [ -h $file_to ] && [ ! -e $file_to ]
|
|
then
|
|
echo -en $B_RED"$file_to is a broken symlink"$ENDCO"\n"
|
|
save_bak $file_to
|
|
elif [ -e $file_to ]
|
|
then
|
|
if [ ! "$(realpath "$file_to")" = "$HERE/config_files/$file_name" ]
|
|
then
|
|
echo -en $YELLOW"$file_to exist but is not the right file"$ENDCO"\n"
|
|
save_bak $file_to
|
|
else
|
|
create_sym=0
|
|
echo -en $YELLOW"$file_to is already the right file"$ENDCO"\n"
|
|
fi
|
|
else
|
|
echo -en $YELLOW"$file_to doesn't exist"$ENDCO"\n"
|
|
fi
|
|
|
|
if [ $create_sym -eq 1 ]
|
|
then
|
|
echo -en $YELLOW"create symlink of "
|
|
echo -en $CYAN"\"$file_name\""
|
|
echo -en $YELLOW" in "
|
|
echo -en $CYAN"\"$path_file_to\""$ENDCO"\n"
|
|
ln -s $HERE/$D_CONFIG_FILES/$file_name $file_to
|
|
fi
|
|
}
|
|
|
|
# receives 1 argument : a chain of acceptables uniques characters (ex: yn)
|
|
function user_choice
|
|
{
|
|
while true; do
|
|
read -n 1 -s choice
|
|
if [[ $choice == [$1] ]]; then
|
|
# the function need to run in a command substitution, and this line gives the result
|
|
echo $choice
|
|
return
|
|
fi
|
|
done
|
|
}
|
|
|
|
|
|
# Ask what to install
|
|
echo "
|
|
(a) Do you want to config all programs: git, screen, zsh, and vim ?
|
|
(c) Or do you want to choose for each of them ?
|
|
|
|
validate by typing the character in parenthesis (-) :
|
|
"
|
|
ASK_INSTALL=$(user_choice "ac")
|
|
|
|
CONFIG_GIT=n
|
|
CONFIG_SCREEN=n
|
|
CONFIG_ZSH=n
|
|
CONFIG_VIM=n
|
|
if [ "$ASK_INSTALL" = "a" ]; then
|
|
CONFIG_GIT=y
|
|
CONFIG_SCREEN=y
|
|
CONFIG_ZSH=y
|
|
CONFIG_VIM=y
|
|
fi
|
|
|
|
|
|
|
|
# config each program :
|
|
|
|
if [ "$ASK_INSTALL" = "c" ]; then
|
|
echo "
|
|
do you want to config git ?
|
|
(y) Yes
|
|
(n) No
|
|
"
|
|
CONFIG_GIT=$(user_choice "yn")
|
|
fi
|
|
if [ "$CONFIG_GIT" = "y" ]; then
|
|
echo "config git"
|
|
echo -e $MAGENTA"make vim default editor for git"$ENDCO
|
|
git config --global core.editor "vim"
|
|
else
|
|
echo "skip git"
|
|
fi
|
|
|
|
if [ "$ASK_INSTALL" = "c" ]; then
|
|
echo "
|
|
do you want to config screen ?
|
|
(y) Yes
|
|
(n) No
|
|
"
|
|
CONFIG_SCREEN=$(user_choice "yn")
|
|
fi
|
|
if [ "$CONFIG_SCREEN" = "y" ]; then
|
|
echo "config screen"
|
|
install "$HOME/.screenrc"
|
|
else
|
|
echo "skip screen"
|
|
fi
|
|
|
|
if [ "$ASK_INSTALL" = "c" ]; then
|
|
echo "
|
|
do you want to config zsh ?
|
|
(y) Yes
|
|
(n) No
|
|
"
|
|
CONFIG_ZSH=$(user_choice "yn")
|
|
fi
|
|
if [ "$CONFIG_ZSH" = "y" ]; then
|
|
echo "config zsh"
|
|
install "$HOME/.zshrc"
|
|
else
|
|
echo "skip zsh"
|
|
fi
|
|
|
|
if [ "$ASK_INSTALL" = "c" ]; then
|
|
echo "
|
|
do you want to config vim ?
|
|
(y) Yes
|
|
(n) No
|
|
"
|
|
CONFIG_VIM=$(user_choice "yn")
|
|
fi
|
|
if [ "$CONFIG_VIM" = "y" ]; then
|
|
echo "config vim"
|
|
install "$HOME/.vimrc"
|
|
install "$HOME/.vim/templates/skeleton_colors.h"
|
|
install "$HOME/.vim/templates/skeleton_tests.hpp"
|
|
install "$HOME/.vim/templates/skeleton.cpp"
|
|
install "$HOME/.vim/templates/skeleton.hpp"
|
|
install "$HOME/.vim/templates/skeleton_main.cpp"
|
|
install "$HOME/.vim/templates/skeleton_makefile"
|
|
else
|
|
echo "skip vim"
|
|
fi
|
|
|