mirror of https://github.com/NvChad/NvChad
skeleton for new install script
parent
6468de54c1
commit
668f1d5623
@ -1,171 +1,98 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
ORANGE='\033[0;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
|
||||||
|
prompt() {
|
||||||
|
case ${1} in
|
||||||
|
"-s" | "--success")
|
||||||
|
printf "${GREEN}%s${NC}\n" "${2}"
|
||||||
|
;;
|
||||||
|
"-e" | "--error")
|
||||||
|
printf "${RED}%s${NC}\n" "${2}"
|
||||||
|
;;
|
||||||
|
"-w" | "--warning")
|
||||||
|
printf "${ORANGE}%s${NC}\n" "${2}"
|
||||||
|
;;
|
||||||
|
"-i" | "--info")
|
||||||
|
printf "${BLUE}%s${NC}\n" "${2}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "${GREEN}%s${NC}\n" "${2}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
_usage() {
|
_usage() {
|
||||||
printf "%s" \
|
printf "%s" \
|
||||||
"Usage: sh ${0##*/} [ options ]
|
"Usage: sh ${0##*/} [ options ]
|
||||||
-h | --help => Show this help.
|
-h | --help => Show this help.
|
||||||
|
|
||||||
-i | --install => Install the config.
|
-i | --install => Install the config.
|
||||||
|
-r | --remove => Remove the config.
|
||||||
-u | --update => Update the existing config without removing existing stuff.
|
-u | --update => Update the existing config without removing existing stuff.
|
||||||
|
|
||||||
-b | --backup 'path' => Custom config backup path.
|
|
||||||
|
|
||||||
-nb | --no-backup => Don't take existing config backup. Use with caution.
|
|
||||||
"
|
"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_check_install_dependencies() {
|
_eval_exit() {
|
||||||
_error_dependencies() {
|
status=$1
|
||||||
printf "%s\n" "Error: Install ${1} before proceeding."
|
suc_msg=$2
|
||||||
exit 1
|
err_msg=$3
|
||||||
}
|
|
||||||
command -v git 1>/dev/null || _error_dependencies git
|
|
||||||
_SED="$(command -v sed)" || _error_dependencies sed
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_check_nvim_version() {
|
|
||||||
version_string="$(nvim --version | grep -Eo 'NVIM.*v[0-9.]+' -m 1 | grep -Eo '[0-9.]+')" || return 1
|
|
||||||
printf "%s\n" "${version_string}" | while IFS=. read -r num1 num2 num3; do
|
|
||||||
{ [ "${num1}" -ge 0 ] && [ "${num2}" -ge 5 ] && [ "${num3}" -ge 0 ]; } || return 1
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
_copy_config() {
|
|
||||||
printf "%s\n" "Linking config"
|
|
||||||
printf "%s\n" "Old nvim config will be changed to nvim.bak if exists! :0"
|
|
||||||
|
|
||||||
# copying config
|
case $status in
|
||||||
if [ -d "${_CONFIG_PATH}" ]; then
|
0)
|
||||||
printf "%s\n" "Nvim Directory exists"
|
prompt -s "${suc_msg}"
|
||||||
if [ "${_NO_BACKUP}" = "true" ]; then
|
;;
|
||||||
printf "%s\n" "Skipping backup as --no-backup flag was passed.."
|
*)
|
||||||
[ "${_UPDATE}" = "false" ] && rm -rf "${_CONFIG_PATH}"
|
prompt -e "${err_msg}"
|
||||||
else
|
;;
|
||||||
printf "%s\n" "Taking backup of existing config.."
|
esac
|
||||||
mv "${_CONFIG_PATH}" "${_BACKUP_PATH}" || {
|
|
||||||
printf "\n%s\n" "Error: Cannot move ${_CONFIG_PATH} to ${_BACKUP_PATH}"
|
|
||||||
printf "\n%s\n" "Take backup manually or use -b/--backup to provide non-empty path or use -nb/--no-backup to skip backup."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
printf "%s\n" "Nvim config doesn't exist, creating it now"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "${_CONFIG_PATH}" || {
|
|
||||||
printf "%s\n" "Error: Cannot create folder ${_CONFIG_PATH}"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
{ cp -r init.lua lua "${_CONFIG_PATH}"/; } || {
|
|
||||||
printf "Error: Couldn't copy nvim config\n"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_setup_terminal_shell() {
|
# _install() {}
|
||||||
_mappings_file="${_CONFIG_PATH}/lua/mappings.lua"
|
_remove() {
|
||||||
# only ask for shellname if running in terminal
|
prompt -i "-> Cleaning '$HOME/.config/nvim/'"
|
||||||
if [ -t 1 ]; then
|
# rm -rf "$HOME/.config/nvim/"
|
||||||
if chsh -l 2>/dev/null 1>&2; then
|
|
||||||
printf "\nAvailable Shells:\n"
|
|
||||||
chsh -l | nl
|
|
||||||
printf "\n%s\n" "Which shell do you want to use? (Eg. 2)"
|
|
||||||
printf "\t%s\n" "[ Enter nothing for current shell ( $_CURRENT_SHELL ) ]"
|
|
||||||
read -r shellnum
|
|
||||||
[ "${shellnum}" -gt 0 ] 2>/dev/null && _SHELLPATH="$(chsh -l | sed -n "$shellnum p")"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# don't try to do any changes user wants their default shell in nvim
|
prompt -i "-> Cleaning '$HOME/.local/share/nvim/'"
|
||||||
if [ -n "$_SHELLPATH" ]; then
|
# rm -rf "$HOME./local/share/nvim/"
|
||||||
# Reference: https://stackoverflow.com/a/4247319
|
|
||||||
# \( & \) will use regex brackets (for later reference with \1)
|
|
||||||
# ( & ) will match text brackets
|
|
||||||
if "${_SED}" --posix -i'.bak' -e "s=^\(map(.* \+*terminal\) \(.*)\)=\1$_SHELLPATH \2=g" "${_mappings_file}"; then
|
|
||||||
printf "%s\n" "=> Neovim shell changed to $_SHELLPATH successfully!"
|
|
||||||
else
|
|
||||||
printf "%s\n" "Cannot edit with sed, edit ${_mappings_file} manually to replace bash with $_SHELLPATH."
|
|
||||||
fi
|
|
||||||
rm -f "${_mappings_file}".bak # delete backup file created by sed
|
|
||||||
fi
|
|
||||||
printf "%s\n" "=> Neovim shell will be ${_SHELLPATH:-${_CURRENT_SHELL}}"
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
_setup_arguments() {
|
# _update() {}
|
||||||
# default variables to be used
|
|
||||||
_CONFIG_PATH="${XDG_CONFIG_HOME:-${HOME}/.config}/nvim"
|
|
||||||
_UPDATE=""
|
|
||||||
_BACKUP_PATH="${_CONFIG_PATH}.bak"
|
|
||||||
_NO_BACKUP="false"
|
|
||||||
_CURRENT_SHELL="${SHELL##*/}"
|
|
||||||
|
|
||||||
_check_longoptions() {
|
|
||||||
[ -z "${2}" ] &&
|
|
||||||
printf '%s: %s: option requires an argument\nTry '"%s -h/--help"' for more information.\n' "${0##*/}" "${1}" "${0##*/}" &&
|
|
||||||
exit 1
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
main() {
|
||||||
case "${1}" in
|
while :; do
|
||||||
-h | --help) _usage ;;
|
case $1 in
|
||||||
-i | --install) _UPDATE="false" ;;
|
-h | -\? | --help)
|
||||||
-u | --update) _UPDATE="true" ;;
|
_usage
|
||||||
-b | --backup)
|
exit 0
|
||||||
_check_longoptions "${1}" "${2}"
|
;;
|
||||||
_BACKUP_PATH="${2}" && shift
|
-i | --install)
|
||||||
|
_install
|
||||||
|
;;
|
||||||
|
-r | --remove)
|
||||||
|
_remove
|
||||||
|
_eval_exit $? "Successfully removeed NvChad!" "Failed to remove NvChad"
|
||||||
|
;;
|
||||||
|
*) # Default case: No more options, so break out of the loop.
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
-nb | --nobackup) _NO_BACKUP="true" ;;
|
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
[ -z "${_UPDATE}" ] && {
|
|
||||||
printf "%s\n" "Error: Either -i/--install or -u/--update flag must be used."
|
|
||||||
printf "%s\n" "See -h/--help for more info."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
printf "%s\n" \
|
|
||||||
"CONFIG PATH: ${_CONFIG_PATH}
|
|
||||||
$(if [ "${_NO_BACKUP}" = "true" ]; then
|
|
||||||
printf "SKIPPING CONFIG BACKUP !\n"
|
|
||||||
else
|
|
||||||
printf "%s\n" "CONFIG BACKUP PATH: ${_BACKUP_PATH}"
|
|
||||||
fi)
|
|
||||||
CURRENT SHELL: ${_CURRENT_SHELL}
|
|
||||||
"
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
init() {
|
||||||
[ $# = 0 ] && _usage
|
if [ $# -eq 0 ]; then
|
||||||
|
prompt -e "ERROR: This script needs at least one argument"
|
||||||
_check_install_dependencies
|
|
||||||
|
|
||||||
_setup_arguments "${@}"
|
|
||||||
_copy_config
|
|
||||||
[ "${_UPDATE}" = "false" ] && _setup_terminal_shell
|
|
||||||
|
|
||||||
# install all plugins + compile them
|
|
||||||
if _NVIM="$(command -v nvim)"; then
|
|
||||||
if _check_nvim_version; then
|
|
||||||
printf "\n%s\n" "=> Neovim will now open." && sleep 1
|
|
||||||
"${_NVIM}" +"autocmd User PackerComplete ++once quitall" \
|
|
||||||
+":lua require 'pluginList' vim.cmd('PackerSync')"
|
|
||||||
"${_NVIM}"
|
|
||||||
else
|
|
||||||
printf "Error: Neovim is installed, but version is lower than 0.5.x, install Neovim >= 5.x and then run nvim & do :PackerSync\n."
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
printf "Error: Neovim is not installed, install Neovim >= 5.x and then run neovim & do :PackerSync.\n"
|
main "${@}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main "${@}"
|
init "${@}"
|
||||||
|
Loading…
Reference in New Issue