Merge pull request #129 from Akianonymus/main

install.sh: Fix all shellcheck warnings | Misc improvements
This commit is contained in:
siduck76 2021-07-05 18:38:43 +05:30 committed by GitHub
commit 1aed70921e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 47 additions and 28 deletions

View File

@ -1,55 +1,74 @@
#!/bin/sh #!/bin/sh
get_platform() { # check if git command is installed
case "$(uname -s)" in command -v git > /dev/null || {
Linux*) platform=Linux ;; printf "Install git before proceeding\n"
Darwin*) platform=Mac ;; exit 1
*) platform="UNKNOWN:${unameOut}" ;;
esac
echo $platform
} }
echo "installing packer" printf "%s\n" "Installing packer"
if [ -d ~/.local/share/nvim/site/pack/packer ]; then if [ -d ~/.local/share/nvim/site/pack/packer ]; then
echo "Clearning previous packer installs" printf "%s\n" "Clearning previous packer installs"
rm -rf ~/.local/share/nvim/site/pack rm -rf ~/.local/share/nvim/site/pack
fi fi
echo "\n=> Installing packer" printf "\n%s\n" "=> Cloning packer.."
git clone https://github.com/wbthomason/packer.nvim \ if git clone https://github.com/wbthomason/packer.nvim \
~/.local/share/nvim/site/pack/packer/start/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim; then
echo "=> packer installed!" printf "%s\n" "=> Packer installed!"
else
printf "Error: Couldn't clone packer\n"
exit 1
fi
echo "Linking config" printf "%s\n" "Linking config"
echo "old nvim config will be changed to nvim.bak if exists! :0" printf "%s\n" "Old nvim config will be changed to nvim.bak if exists! :0"
# copying config # copying config
if [ -d ~/.config/nvim ]; then if [ -d ~/.config/nvim ]; then
echo "Nvim Directory exists" printf "%s\n" "Nvim Directory exists"
echo "Changing nvim to nvim.bak" printf "%s\n" "Changing nvim to nvim.bak"
mv ~/.config/nvim/ ~/.config/nvim.bak/ mv ~/.config/nvim/ ~/.config/nvim.bak/
echo "Creating new nvim directory" printf "%s\n" "Creating new nvim directory"
mkdir -p ~/.config/nvim mkdir -p ~/.config/nvim
else else
echo "Nvim Config doesn't exist so creating one" printf "%s\n" "Nvim Config doesn't exist so creating one"
mkdir -p ~/.config/nvim/ mkdir -p ~/.config/nvim/
fi fi
cp -r init.lua ~/.config/nvim/ && cp -r lua ~/.config/nvim/ { cp -r init.lua ~/.config/nvim/ && cp -r lua ~/.config/nvim/ ;} || {
printf "Error: Couldn't copy nvim config\n"
exit 1
}
# change shell in nvim config # change shell in nvim config
read -p "which shell do you use?: " shellname _CURRENT_SHELL="${SHELL##*/}"
echo "$shellname" printf "%s\n: " "Which shell do you want to use ? [ Enter nothing for current shell ( $_CURRENT_SHELL ) ]"
read -r shellname
shellname="${shellname:-${_CURRENT_SHELL}}"
printf "%s\n" "$shellname"
if [ "$(get_platform)" = "Mac" ]; then # don't try to do any changes if given shellname is same as bash
gsed -i "s/bash/$shellname/g" ~/.config/nvim/lua/mappings.lua if ! [ bash = "$shellname" ]; then
# Reference: https://stackoverflow.com/a/4247319
if "$(command -v sed)" -i'.bak' -e "s/bash/$shellname/g" ~/.config/nvim/lua/mappings.lua; then
printf "\n%s\n" "=> Shell changed to $shellname on nvim successfully!"
else else
sed -i "s/bash/$shellname/g" ~/.config/nvim/lua/mappings.lua printf "\n%s\n" "Cannot edit with sed, edit ~/.config/nvim/lua/mappings.lua manually to replace bash with $shellname."
fi
rm -f ~/.config/nvim/lua/mappings.lua.bak # delete backup file created by sed
else
printf "\n%s\n" "=> Shell changed to $shellname on nvim successfully!"
fi fi
echo "\n=> shell changed to $shellname on nvim successfully!" printf "\n%s\n" "=> Neovim will open with some errors, just press enter" && sleep 1
echo "\n=> neovim will open with some errors , just press enter" && sleep 1
# install all plugins + compile them # install all plugins + compile them
nvim +PackerSync if _NVIM="$(command -v nvim)"; then
"${_NVIM}" +PackerSync
else
printf "Error: Neovim is not installed, install Neovim >= 5.x and then run the below command\n"
printf " nvim +PackerSync\n"
exit 1
fi