From 93675f81a94864b9148633229388663e65749c0c Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Tue, 4 Jan 2022 20:43:30 +0100 Subject: [PATCH] [AUTOCONFIG] Add neovim autoconfig from .env --- .env | 11 +++ install.sh | 36 +++++++--- install_scripts/ubuntu.sh | 118 -------------------------------- scripts/common.sh | 22 ++++++ scripts/tools/neovim/install.sh | 21 ++++++ 5 files changed, 79 insertions(+), 129 deletions(-) create mode 100644 .env mode change 100644 => 100755 install.sh delete mode 100644 install_scripts/ubuntu.sh create mode 100755 scripts/common.sh create mode 100755 scripts/tools/neovim/install.sh diff --git a/.env b/.env new file mode 100644 index 0000000..af237eb --- /dev/null +++ b/.env @@ -0,0 +1,11 @@ +# CURRENT SELECTED CONFIGURATION + +# Available configuration (bash, zsh, fish) +SHELL=zsh + +# Available configuration (awesome, i3) +WM=awesome + +# Install neovim with custom configuration +WITH_NEOVIM=yes + diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index 269eb10..5c2a52a --- a/install.sh +++ b/install.sh @@ -1,14 +1,28 @@ #!/bin/bash +source ./scripts/common.sh -OS_NAME=`cat /etc/os-release | grep "^NAME=" | sed 's/NAME=//g' | sed 's/"//g'` -OS_NAME=${OS_NAME^^} # UPPERCASE +if [ -f .env ]; then + # Load Environment Variables + export $(cat .env | grep -v '#' | awk '/=/ {print $1}') + echo "[INFO] Environment file loaded" +fi +export OS_NAME=`cat /etc/os-release | grep "^NAME=" | sed 's/NAME=//g' | sed 's/"//g'` +export OS_NAME=${OS_NAME,,} # LOWERCASE +export CWD=$(pwd) -case $OS_NAME in - "UBUNTU") - source ./install_scripts/ubuntu.sh - start - ;; - *) - echo "OS not supported" - ;; -esac \ No newline at end of file +# Initialize + +## Detect current package manager +command_exists pacman && export PM=pacman + +if ! [[ -z "${PM}" ]]; then + echo "[INFO] Package manager set to : $PM" +else + echo '[ERROR] No package manager found. Aborting...' >&2 +fi + + +find ./scripts -type f -iname "*.sh" -exec chmod +x {} \; + +# Install and configure functionality +./scripts/tools/neovim/install.sh \ No newline at end of file diff --git a/install_scripts/ubuntu.sh b/install_scripts/ubuntu.sh deleted file mode 100644 index 1222b1f..0000000 --- a/install_scripts/ubuntu.sh +++ /dev/null @@ -1,118 +0,0 @@ -refresh_repo () { - echo "Refreshing repo..." - sudo apt update -} - -install_fish() { - refresh_repo - echo "Installing fish..." - sudo apt install fish -y - echo "Success" - read -p "Install oh-my-fish ? (y/n) [n] " ok - case $ok in - [yY]*) - curl -L https://get.oh-my.fish | fish - echo "Success" - ;; - *) - echo "No modification" - ;; - esac - read -p "Set to default shell ? (y/n) [n] " ok - case $ok in - [yY]*) - FISH_BIN=`which fish` - chsh -s "$FISH_BIN" "$USER" - echo "Success" - ;; - *) - echo "No modification" - ;; - esac - read -p "Install agnoster theme ? (y/n) [n] " ok - case $ok in - [yY]*) - fish -c "omf install agnoster" - echo "Success" - ;; - *) - echo "No modification" - ;; - esac -} - -install_zsh() { - refresh_repo - echo "Installing zsh..." - sudo apt install zsh -y - echo "Success" - read -p "Install oh-my-zsh ? (y/n) [n] " ok - case $ok in - [yY]*) - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" - echo "Success" - ;; - *) - echo "No modification" - ;; - esac - read -p "Set to default shell ? (y/n) [n] " ok - case $ok in - [yY]*) - ZSH_BIN=`which zsh` - chsh -s "$ZSH_BIN" "$USER" - echo "Success" - ;; - *) - echo "No modification" - ;; - esac -} - -install_neovim () { - sudo add-apt-repository ppa:neovim-ppa/unstable -y - refresh_repo - sudo apt-get install neovim -y - echo "Success" - read -p "Install custom config (Warning : Erase old conf) ? (y/n) [n] " ok - case $ok in - [yY]*) - rm -rf ~/.config/nvim - mkdir -p ~/.config/nvim - cp -r ./configs/nvim/* ~/.config/nvim - refresh_repo - sudo apt install ripgrep ruby-dev -y - gem install --user-install solargraph - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - source ~/.cargo/env - ;; - *) - echo "No modification" - ;; - esac -} - - -start () { - read -p "Select you shell. (0 - current, 1 - fish, 2 - zsh) [0] " shell - case $shell in - "1") - install_fish - ;; - "2") - install_zsh - ;; - *) - echo "No modification" - ;; - esac - read -p "Install nvim 0.5 ? (y/n) [n] " ok - case $ok in - [yY]*) - install_neovim - ;; - *) - echo "No modification" - ;; - esac -} diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100755 index 0000000..d8be94f --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,22 @@ +#!/bin/bash +command_exists () { + type "$1" &> /dev/null +} + +install_package () { + if [[ "$PM" == 'pacman' ]]; then + sudo pacman -S --noconfirm "$@" + echo "[INFO] Finished to install $@" + else + echo '[ERROR] Package manager not supported' >&2 + fi +} + +remove_package () { + if [[ "$PM" == 'pacman' ]]; then + sudo pacman -R --noconfirm "$@" + echo "[INFO] Finished to remove $@" + else + echo '[ERROR] Package manager not supported' >&2 + fi +} \ No newline at end of file diff --git a/scripts/tools/neovim/install.sh b/scripts/tools/neovim/install.sh new file mode 100755 index 0000000..61f88aa --- /dev/null +++ b/scripts/tools/neovim/install.sh @@ -0,0 +1,21 @@ +source ./scripts/common.sh + +if [[ "$WITH_NEOVIM" == 'yes' ]]; then + if ! command_exists nvim; then + install_package neovim + echo '[INFO] Neovim installed' + else + echo '[INFO] Neovim already installed' + fi + + if [[ ! -d "$HOME/.config/nvim" ]]; then + ln -s "$CWD/configs/nvim" "$HOME/.config/nvim" + echo "[INFO] Neovim config linked with symbolic link : $CWD/configs/nvim -> $HOME/.config/nvim" + + install_package ripgrep fd dart lazygit rust-analyzer lldb + else + echo '[INFO] Neovim config already linked' + fi +else + echo '[INFO] WITH_NEOVIM not equals to yes. Ignoring...' +fi \ No newline at end of file