Skip to content

Instantly share code, notes, and snippets.

@KasRoudra
Created December 30, 2022 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KasRoudra/f8a127b746c5b965621a52e7061329cf to your computer and use it in GitHub Desktop.
Save KasRoudra/f8a127b746c5b965621a52e7061329cf to your computer and use it in GitHub Desktop.
Neovim distributions manager
#!/usr/bin/env bash
# Color snippets
black="\033[0;30m"
red="\033[0;31m"
bred="\033[1;31m"
green="\033[0;32m"
bgreen="\033[1;32m"
yellow="\033[0;33m"
byellow="\033[1;33m"
blue="\033[0;34m"
bblue="\033[1;34m"
purple="\033[0;35m"
bpurple="\033[1;35m"
cyan="\033[0;36m"
bcyan="\033[1;36m"
white="\033[0;37m"
nc="\033[00m"
nvdmDir="$HOME/nvims"
configDir="$HOME/.config/nvim"
pluginDir="$HOME/.local/share/nvim"
cacheDir="$HOME/.cache/nvim"
configBackup="${configDir}.backup"
pluginBackup="${pluginBackup}.backup"
logo="
_ ___ ______ __ __
| \ | \ \ / / _ \| \/ |
| \| |\ \ / /| | | | |\/| |
| |\ | \ V / | |_| | | | |
|_| \_| \_/ |____/|_| |_|
A neovim distribution manager
"
declare -A repoArray=(
[astro]=AstroNvim
[cosmic]=CosmicNvim
[nvchad]=NvChad
[space]=SpaceVim
)
print() {
text="$1"
if ! command -v lolcat &> /dev/null; then
echo -e "$text" | lolcat
else
echo -e "$text"
fi
}
info() {
print "${yellow}[${white}+${yellow}] ${cyan}${1}${nc}"
sleep 1
}
info2() {
print "${green}[${white}+${green}] ${purple}${1}${nc}"
sleep 1
}
success() {
print "${cyan}[${white}✔${cyan}] ${green}${1}${nc}"
sleep 1
}
error() {
print "${blue}[${white}✘${blue}] ${red}${1}${nc}"
sleep 1
}
backup() {
if [ -d "$configBackup" ]; then
info "Removing old neovim backup..."
rm -rf "$configBackup"
rm -rf "$pluginBackup"
fi
if [ -d "$configDir" ]; then
info2 "Backing up neovim configuration..."
cp -r "$configDir" "$configBackup"
cp -r "$pluginDir" "$pluginBackup"
fi
}
checkDir() {
dist="$1"
if [ -d "$nvdmDir/$dist" ]; then
echo true
else
echo false
fi
}
clone() {
dist="$1"
repo="${repoArray[$dist]}"
mkdir -p $nvdmDir/$dist
info "Downloading $1...."
git clone https://github.com/$repo/$repo $nvdmDir/$dist/config
}
copy() {
dist="$1"
remove
info2 "Configuring neovim...."
cp -r $nvdmDir/$dist/config $configDir
cp -r $nvdmDir/$dist/plugins $pluginDir
}
delete() {
dist="$1"
rm -rf $nvdmDir/$dest/config $nvdmDir/$dest/plugins
}
manage() {
dist="$1"
isInstalled=$(checkDir $dist)
if !isInstalled; then
clone $dist
info2 "Installing $1 plugins. This may take a while!"
nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync'
cp -r $pluginDir $nvdmDir/$dist/plugins
fi
}
main () {
print "$logo"
if [ $# -gt 0 ]; then
case $1 in
astro|cosmic|nvchad|space)
dist="$1"
manage $dist
copy $dist
;;
backup)
backup
;;
install)
dist="$2"
case $dist in
astro|cosmic|nvchad|space)
manage $dist
;;
*)
error "No distribution named $dist!"
;;
esac
;;
restore)
restore
;;
remove|uninstall|delete)
dist="$2"
case $dist in
astro|cosmic|nvchad|space)
delete $dist
;;
*)
error "No distribution named $dist!"
;;
esac
;;
*)
error "Unknown command $1!"
exit 0
;;
esac
else
manage astro
manage cosmic
manage nvchad
manage space
fi
}
remove() {
info "Removing current neovim configuration...."
rm -rf $configDir $pluginDir $cacheDir
}
restore() {
remove
info2 "Restoring neovim from backup...."
if [ -d "$configBackup" ]; then
cp -r "$configBackup" "$configDir"
cp -r "$pluginBackup" "$pluginDir"
fi
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment