mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
118 lines
2.8 KiB
Bash
Executable File
118 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
set -e
|
|
|
|
config="${HOME}/.config"
|
|
uninstall=1
|
|
remove=1
|
|
copy=1
|
|
link=0
|
|
|
|
_usage() {
|
|
printf "\n" >&2
|
|
printf "Usage: setup [OPTIONS]\n" >&2
|
|
printf "\n" >&2
|
|
printf "Installs or Uninstalls nvim configuration files.\n" >&2
|
|
printf "\n" >&2
|
|
printf "Options:\n" >&2
|
|
printf "\t-c | --copy : Copy the configuration files, instead of creating symlinks.\n" >&2
|
|
printf "\t-h | --help : Print usage information.\n" >&2
|
|
printf "\t-l | --link : Create symlinks to the configuration files (Default).\n" >&2
|
|
printf "\t-r | --remove : Removes the entire ~/.config/nvim directory.\n" >&2
|
|
printf "\t-u | --uninstall : Uninstalls configuration files.\n" >&2
|
|
printf "\n" >&2
|
|
printf "If called without the uninstall option then it will install the configuration files.\n" >&2
|
|
printf "The copy and link options are ignored if called with the uninstall or remove option.\n" >&2
|
|
printf "\n" >&2
|
|
}
|
|
|
|
_parse_options() {
|
|
arg=
|
|
while ! test -z "$1"; do
|
|
arg="$1"
|
|
case $arg in
|
|
-c | --copy)
|
|
copy=0
|
|
link=1
|
|
shift;;
|
|
-h | --help)
|
|
_usage
|
|
exit;;
|
|
-l | --link)
|
|
copy=1
|
|
link=0
|
|
shift;;
|
|
-r | --remove)
|
|
remove=0
|
|
shift;;
|
|
-u | --uninstall)
|
|
uninstall=0
|
|
shift;;
|
|
*)
|
|
echo "Unknown option $arg" >&2
|
|
shift;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
_make_dirs() {
|
|
if ! test -d "${config}"; then
|
|
mkdir "${config}"
|
|
fi
|
|
if ! test -d "${config}/nvim"; then
|
|
mkdir "${config}/nvim"
|
|
fi
|
|
}
|
|
|
|
_remove_nvim() {
|
|
echo "Removing nvim configuration..." >&2
|
|
test -d "${config}/nvim" && rm -r "${config}/nvim"
|
|
}
|
|
|
|
_uninstall_nvim() {
|
|
echo "Uninstalling nvim configuration..." >&2
|
|
test -e "${config}/nvim/init.lua" && rm "${config}/nvim/init.lua"
|
|
test -d "${config}/nvim/lua" && rm "${config}/nvim/lua"
|
|
}
|
|
|
|
_link_nvim() {
|
|
echo "Linking nvim configuration..." >&2
|
|
ln -sfv "${PWD}/init.lua" "${config}/nvim"
|
|
ln -sfv "${PWD}/lua" "${config}/nvim"
|
|
}
|
|
|
|
_copy_nvim() {
|
|
echo "Linking nvim configuration..." >&2
|
|
cp "${PWD}/init.lua" "${config}/nvim"
|
|
cp -r "${PWD}/lua" "${config}/nvim"
|
|
}
|
|
|
|
_install_nvim() {
|
|
_make_dirs
|
|
# copy if in copy mode
|
|
test "$copy" -eq 0 && _copy_nvim && exit "$?"
|
|
# link if in link mode
|
|
test "$link" -eq 0 && _link_nvim && exit "$?"
|
|
# else we don't know what to do
|
|
echo "Neither link or copy options were set. Use the --help option for usage." >&2
|
|
exit 1
|
|
}
|
|
|
|
#------------------------------- main ------------------------------
|
|
|
|
main() {
|
|
_parse_options "$@"
|
|
|
|
# check if remove is called first
|
|
test "$remove" -eq 0 && _remove_nvim && exit "$?"
|
|
|
|
# then check if uninstall was called
|
|
test "$uninstall" -eq 0 && _uninstall_nvim && exit "$?"
|
|
|
|
# else install the configuration files
|
|
_install_nvim
|
|
echo "Nvim will need to be started and call :PackerSync for plugins to be downloaded." >&2
|
|
}
|
|
|
|
main "$@"
|