mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
Working on install script(s)
This commit is contained in:
105
vim/setup
105
vim/setup
@@ -2,14 +2,109 @@
|
||||
|
||||
set -e
|
||||
|
||||
if test -z "$(type vim)"; then
|
||||
echo "Does not look like you have vim installed."
|
||||
vim_dir="${HOME}/.vim"
|
||||
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 vim 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 "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 ~/.vim directory.\n" >&2
|
||||
printf "\t-u | --uninstall: Uninstalls configuration files.\n" >&2
|
||||
printf "" >&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 "${vim_dir}"; then
|
||||
mkdir "${vim_dir}"
|
||||
fi
|
||||
}
|
||||
|
||||
_uninstall_vim() {
|
||||
echo "Uninstalling vim..." >&2
|
||||
test -e "${vim_dir}/vimrc" && rm "${vim_dir}/vimrc"
|
||||
}
|
||||
|
||||
_remove_vim() {
|
||||
echo "Removing ~/.vim..." >&2
|
||||
test -d "${vim_dir}" && rm -r -i "${vim_dir}"
|
||||
}
|
||||
|
||||
_link_vim() {
|
||||
echo "Symlinking vim configuration files..." >&2
|
||||
ln -sfv "${PWD}/vimrc" "${vim_dir}"
|
||||
}
|
||||
|
||||
_copy_vim() {
|
||||
echo "Copying vim configuration files..." >&2
|
||||
cp "${PWD}/vimrc" "${vim_dir}"
|
||||
}
|
||||
|
||||
_install_vim() {
|
||||
_make_dirs
|
||||
# check if in copy mode & copy configuration
|
||||
test "$copy" -eq 0 && _copy_vim && return 0
|
||||
# else check if in link mode & link configuration
|
||||
test "$link" -eq 0 && _link_vim && return 0
|
||||
# we don't know what to do w/o link or copy so error
|
||||
echo "Must supply the link or copy option, use --help for usage" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
mkdir "${HOME}/.vim" >/dev/null 2>&1
|
||||
ln -sfv "${PWD}/.vim/vimrc" "${HOME}/.vim/vimrc"
|
||||
#------------------------------- main -------------------------------
|
||||
|
||||
main() {
|
||||
_parse_options "$@"
|
||||
|
||||
# check if remove is called first
|
||||
test $remove -eq 0 && _remove_vim && exit
|
||||
|
||||
# then check if uninstall was called
|
||||
test $uninstall -eq 0 && _uninstall_vim && exit
|
||||
|
||||
# else install the configuration files
|
||||
_install_vim
|
||||
echo "Vim will need to be started, vim plugins should download on start or call :PlugInstall."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user