Skip to content

Instantly share code, notes, and snippets.

@EVODelavega
Created November 14, 2019 14:01
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 EVODelavega/8ab4c627f6fbfcdd00588480852fce7d to your computer and use it in GitHub Desktop.
Save EVODelavega/8ab4c627f6fbfcdd00588480852fce7d to your computer and use it in GitHub Desktop.
Quick script to reinstall YCM once it's borked because of vim-plug not updating it correctly
#!/usr/bin/env bash
## just so we can return to pwd at the end
current_dir="$(pwd)"
## path where vim plugins are found (subdirectory based on plugin manager not included)
vim_path="${HOME}/.vim"
## path under vim directory (default ~/.vim) where YCM is installed
install_path="plugged"
## YCM directory name
ycm_dir="YouCompleteMe"
## YCM Repo
ycm_repo="https://github.com/Valloric/YouCompleteMe.git"
## specify a python bin, if you need python3, but your distro defaults to 2.7, use -p python3
python_bin=""
## the script to install
install_script="install.py"
## install flags
ycm_flags="--clang-completer"
Usage() {
cat <<-__EOF_
${0##*/} Update YCM installation (because vim-plug is broken)
-v <path> : Vim path where all things vim are related (excluding plugin dir) [default: ${vim_path}]
-p <path> : Plugin path, under vim path, depends on plugin manager [default: ${install_path}]
-Y <path> : Optional rename of the target path into which YCM must be stored [default: ${ycm_dir}]
-r <repo> : The URL of the git repo where the latest YCM version can be found [default: ${ycm_repo}]
-P <bin> : A specific python bin to use, hashbang of install script is used by default
-s <script>: Specify the install script to use [default: ${install_script}]
-f <flags> : Specify the install flags [default: ${ycm_flags}]
-h : Display help message
Examples:
${0##*/}
Reinstalls YCM in ${vim_path}/${install_path}/${ycm_dir} using the command ./${install_script} ${ycm_flags}
${0##*/} -P python3
Reinstalls YCM in ${vim_path}/${install_path}/${ycm_dir} using the command python3 ${install_script} ${ycm_flags}
${0##*/} -v /root/.vim -f "--clang-completer --debug"
Reinstalls YCM in /root/.vim/${install_path}/${ycm_dir} using the command ./${install_script} --clang-completer --debug
__EOF_
}
while getopts :v:p:Y:r:P:s:f:h f; do
case $f in
v)
vim_path="${OPTARG}"
;;
p)
install_path="${OPTARG}"
;;
Y)
ycm_dir="${OPTARG}"
;;
r)
ycm_repo="${OPTARG}"
;;
P)
python_bin="${OPTARG}"
;;
s)
install_script="${OPTARG}"
;;
f)
ycm_flags="${OPTARG}"
;;
h)
Usage
exit 0
;;
*)
echo "ERROR: UNKNOWN OPTION ${f}${OPTARG}"
Usage
exit 1
;;
esac
done
if [ ! -d "${vim_path}/${install_path}" ]; then
echo "${vim_path}/${install_path} is not a valid directory"
exit 1
fi
## Let's go to the path where we'll find YCM
cd "${vim_path}/${install_path}"
## Remove the old version, if installed
[ -d "${ycm_dir}" ] && rm -rf "${ycm_dir}"
echo "Getting most recent version of YCM into ${ycm_dir}"
git clone "${ycm_repo}" "${ycm_dir}" || exit 1
if [ ! -e "${ycm_dir}/${install_script}" ]; then
echo "ERROR: ${ycm_dir}/${install_script} not found"
exit 1
fi
cd "${ycm_dir}"
echo "Updating the submodules... (which are a right PITA)"
git submodule update --init --recursive || exit 1
echo "Installing/compiling YCM"
if [ -z "${python_bin}" ]; then
./ "${install_script}" "${ycm_flags}"
exit
fi
## build command
commad=("${python_bin}" "${install_script}" "${flags}")
## now run it
"${command[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment