install(){
  echo -e "INSTALLATION DE VIMSCODE\r"
  echo -e 'Installation en cours : [--------------------](0%)\r'
  sudo apt update > /dev/null 2>&1
  sudo apt install elinks figlet -y > /dev/null 2>&1
  echo -e 'Installation en cours : [#####---------------](25%)\r'

  mkdir ~/.vim && mv * ~/.vim 
  cd ~/.vim && mv vimrc-conf ~/.vimrc && mv vimrc2-conf ~/.vimrc2
  cd ~/.vim/bundle/ && git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim > /dev/null 2>&1
  sudo mv ~/.vim/install.sh /bin/ 
  echo -e 'Installation en cours : [##########----------](50%)\r'

  echo "Utilisez-vous bash ou zsh ?"
  read -r term

  if [ "$term" = "bash" ]; then
    if ! cat ~/.bashrc | grep -q 'alias vimscode="/bin/vimscode.sh"'; then
      echo 'alias vimscode="/bin/vimscode.sh"' >> ~/.bashrc
    fi
  else
    if ! cat ~/.zshrc | grep -q 'alias vimscode="/bin/vimscode.sh"'; then 
      echo 'alias vimscode="/bin/vimscode.sh"' >> ~/.zshrc
    fi
  fi
  echo -e 'Configuration en cours : [###############-----](75%)\r'

  vim -u ~/.vimrc2 -c PluginInstall -c q -c q > /dev/null 2>&1
  rm -rf ~/.vimrc2
  echo -e 'Configuration en cours : [####################](100%)\r'

  echo "Installation terminée."
}

# Fonction pour la mises a jour de Vimscode
maj(){

  echo -e "Mise à jour en cours..."
  echo -e 'Début de la mise à jour : [-----------------](0%)\r'
  rm -rf  ~/.vim ~/.vimrc
  git clone https://git.cohabit.fr/bastien/VimsCode.git > /dev/null 2>&1 && cd VimsCode

  mkdir ~/.vim && mv * ~/.vim 
  cd ~/.vim && mv vimrc-conf ~/.vimrc && mv vimrc2-conf ~/.vimrc2
  cd ~/.vim/bundle/ && git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim > /dev/null 2>&1
  echo -e 'Mise à jour en cours : [#####---------------](25%)\r'

  echo "Utilisez-vous bash ou zsh ?"
  read -r term

  if [ "$term" = "bash" ]; then
    if ! cat ~/.bashrc | grep -q 'alias vimscode="/bin/vimscode.sh"'; then
      echo 'alias vimscode="/bin/vimscode.sh"' >> ~/.bashrc
    fi
  else
    if ! cat ~/.zshrc | grep -q 'alias vimscode="/bin/vimscode.sh"'; then 
      echo 'alias vimscode="/bin/vimscode.sh"' >> ~/.zshrc
    fi
  fi
  echo -e 'Mise à jour en cours : [##########----------](50%)\r'
  
  vim -u ~/.vimrc2 -c PluginInstall -c q -c q > /dev/null 2>&1
  rm -rf ~/.vimrc2
  echo -e 'Mise à jour en cours : [###############-----](75%)\r'
 
  cd ../ && rm -rf Vimscode 
  echo -e 'Mise à jour fini : [####################](100%)\r'
  echo -e "Mise à jour terminé."
}

if [ "$1" = "-maj" ]; then
  maj
elif [ "$1" = '-install' ] ; then
  install
elif [ "$1" = '-a' ] || [ "$1" = '-arduino' ] ; then
        vim -p $2 ~/.vim/help/En/help-arduino
elif [ "$1" = '-e' ] || [ "$1" = '-esp' ] ; then
        vim -p $2 ~/.vim/help/En/help-esp32
elif [ "$1" = '-p' ] || [ "$1" = '-platform.io' ] ; then
        vim -p $2 ~/.vim/help/En/help-platform.io
elif [ "$1" = '' ] || [ "$1" = '' ] ; then
        cat ~/.vim/help/help-vimscode
else
  echo "Commande invalide"
fi