Added a new script that can be used to update the repo if bash is
available. Updated the README. Improved the theme by adding a bunch
of syntax highlighting definitions (mostly rooted in html, though
a bunch of other languages base their colours on it), as well as
tweaking visual selection to longer invert on the block with the cursor,
and parenthesis matching to look the same at both ends. Added a plugin
that improves the theme and adds some keyboard shortcuts to markdown,
which is what the README.md files in Github are written in. I realized
that the h,j,k,l shortcuts equivalent to the ones with arrow keys I'd
added were overwriting other shortcuts with the shift combinations, so
I removed those and the ctrl-ones for consistency. The diff shortcuts
weren't intuitive or easy on the hands, so I tried something else and
I think it works much better now (check vim/keyboard.vim). An update
script has also been added to simplify updating submodules; I'm not
completely clear as to whether following this method will properly
update the submodules in certain conditions like when one is removed,
but this should add new ones and update the existing ones after pulling
from the repo.
2014-04-01 00:03:52 -04:00
#!/usr/bin/env bash
2015-01-21 01:51:48 -05:00
#
# Darkcloud Vim Config Update Tool
# https://github.com/prurigro/darkcloud-vimconfig
#
# Written by Kevin MacMartin (prurigro@gmail.com)
# Released under the MIT license
#
2024-03-05 21:17:56 -05:00
#
# VARIABLES
#
error_log=update-errors.log
2015-02-17 12:39:08 -05:00
script_name="${0//*\/}"
2024-03-05 21:17:56 -05:00
script_home="${0%"$script_name"}"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if [[ -z "$script_home" ]]; then
script_home="$PWD"
else
2018-03-11 22:55:51 -04:00
pushd "$script_home" >/dev/null || exit
2015-03-14 02:22:25 -04:00
script_home="$PWD"
2018-03-11 22:55:51 -04:00
popd >/dev/null || exit
2015-03-14 02:22:25 -04:00
fi
2016-09-29 11:46:56 -04:00
2018-03-11 22:55:51 -04:00
if [[ -t 1 ]]; then
2015-02-17 12:39:08 -05:00
cbg_blue=$'\e[44m'
cbg_red_bold=$'\e[1;41m'
cbg_black=$'\e[40m'
cbg_yellow=$'\e[43m'
cfg_green_bold=$'\e[1;32m'
cfg_red_bold=$'\e[1;31m'
cfg_white_bold=$'\e[1;37m'
c_reset=$'\e[0m'
2018-03-11 22:55:51 -04:00
else
2015-02-17 12:39:08 -05:00
cbg_blue='#'
2018-03-11 22:55:51 -04:00
fi
2015-01-21 01:51:48 -05:00
2024-03-05 21:17:56 -05:00
#
# FUNCTIONS
#
2015-01-21 01:51:48 -05:00
# error: output and log error
2015-03-14 02:22:25 -04:00
function error {
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cbg_blue $c_reset$cbg_red_bold ! ERROR: $c_reset$cfg_red_bold $2 " >&2
printf '%s\n' "$cbg_blue $c_reset$cbg_red_bold ! COMMAND: $c_reset ${cfg_white_bold}=> $1$c_reset" >&2
2018-03-11 22:55:51 -04:00
[[ -n "$3" ]] && printf '%s\n' "$cbg_blue $c_reset$cbg_red_bold ! OUTPUT: $c_reset$cfg_white_bold $3" >&2
2015-02-17 12:39:08 -05:00
printf '%s\n%s\n%s\n' "DATE: @ $(date)" "ERROR: $2" "COMMAND: $1" >> "$script_home/$error_log"
2018-03-11 22:55:51 -04:00
[[ -n "$3" ]] && printf '%s\n' "OUTPUT: $3" >> "$script_home/$error_log"
2015-02-17 12:39:08 -05:00
printf '\n' >> "$script_home/$error_log"
2014-06-16 05:37:52 -04:00
}
2014-06-17 08:19:40 -04:00
# show_version: displays version information
2015-03-14 02:22:25 -04:00
function show_version {
2024-03-05 21:17:56 -05:00
repo_version="$(printf "%s.r%s" "$(git show -s --format=%ci master | sed 's/\ .*//g;s/-//g')" "$(git rev-list --count HEAD)")"
2015-02-17 12:39:08 -05:00
printf '%s\n' "$script_name: darkcloud-vimconfig update tool (version: $repo_version)"
2014-06-17 01:49:46 -04:00
}
2014-06-17 08:19:40 -04:00
# show_help: this function displays help output
2015-03-14 02:22:25 -04:00
function show_help {
2015-02-17 12:39:08 -05:00
printf '\n%s\n' 'USAGE'
printf ' %s\n\n' "./$script_name [OPTION]"
printf '%s\n' 'OPTIONS'
printf ' %s\t%s\n' '-v, --version' '| output version information and exit'
printf ' %s\t%s\n\n' '-h, --help' '| display this help and exit'
printf '%s\n' 'Run with no arguments to update darkcloud-vimconfig'
2014-06-17 01:49:46 -04:00
}
2014-06-17 08:19:40 -04:00
2024-03-05 21:17:56 -05:00
#
# SETUP
#
2016-09-29 11:46:56 -04:00
if type -P timeout >/dev/null; then
timeout_command=timeout
elif type -P gtimeout >/dev/null; then
timeout_command=gtimeout
else
error 'type -P timeout' 'The timeout command could not be found (install coreutils)'
exit 1
fi
2016-09-06 12:24:56 -04:00
cd "$script_home" || exit
2014-06-17 01:49:46 -04:00
2014-06-17 08:19:40 -04:00
# delete old error log if it exists
2018-03-11 22:55:51 -04:00
[[ -f "$error_log" ]] && rm "$script_home/$error_log"
2014-06-17 08:19:40 -04:00
# parse for arguments (then handle them below)
2015-01-21 01:51:48 -05:00
[[ -n "$1" ]] && {
case "$1" in
-h|--help)
show_version
show_help
exit 0
;;
-v|--version)
show_version
exit 0
;;
*)
error "$ERROR" "$1 is not a valid option"
show_help
exit 1
;;
esac
}
2014-06-17 08:19:40 -04:00
2015-01-21 01:51:48 -05:00
# display script title
2015-02-17 12:39:08 -05:00
printf '\n%s\n' "$cbg_black ~~~ DarkCloud Vimconfig Update Tool ~~~ $c_reset"
2015-01-21 01:51:48 -05:00
# create vim/bundle.user if it doesn't exist
2015-02-17 12:39:08 -05:00
[[ -d 'vim/bundle.user' ]] || {
printf '\n%s' "$cbg_blue >> Creating user plugin directory:$c_reset"
process_status="$(install -d 'vim/bundle.user' 2>&1)"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
error 'install -d vim/bundle.user' "User plugin directory couldn't be created" "$process_status"
fi
2015-01-21 01:51:48 -05:00
}
# create vim/vimrc.user if it doesn't exist
2015-02-17 12:39:08 -05:00
[[ -e 'vim/vimrc.user' ]] || {
printf '\n%s' "$cbg_blue >> Creating user config file:$c_reset"
process_status="$(touch 'vim/vimrc.user' 2>&1)"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
{
2018-03-11 23:34:49 -04:00
printf '%s\n%s\n\n' '"Autocheck syntax checking: (1:start toggled on | *0:start toggled off)' '"let g:autostartchecker = 0'
printf '%s\n%s\n\n' '"Autoload Tagbar: (1:start open | *0:start closed)' '"let g:autostarttagbar = 0'
2018-03-13 15:38:03 -04:00
printf '%s\n%s\n\n' '"Disable Completion: (1:disable completion | *0:enable completion if requirements are met)' '"let g:disablecompletion = 0'
2018-03-11 23:34:49 -04:00
printf '%s\n%s\n\n' '"Disable automatic tag generation and highlighting: (1:force disabled tag generation and highlighting | *0:enable automatic tag generation and highlighting)' '"let g:disableautotags = 0'
printf '%s\n%s\n\n' '"Disable automatic linebreaking: (1:force disabled globally | *0:let the filetype decide)' '"let g:disablelinebreaks = 0'
printf '%s\n%s\n\n' '"Enable Powerline fonts: (1:expect powerline font | *0:expect regular font)' '"let g:powerlinefonts = 0 "(set powerline font for gvim and terminal when enabled)'
2015-02-17 12:39:08 -05:00
printf '%s\n%s\n' '"GVim font selection: (Escaping spaces and use powerline if appropriate)' '"set guifont=Monospace\ 12'
} >> vim/vimrc.user
2016-09-29 11:46:56 -04:00
2015-02-17 12:39:08 -05:00
if [[ -e 'vim/vimrc.user' ]]; then
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
fi
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
error "touch vim/vimrc.user" "User config couldn't be created" "$process_status"
fi
2015-01-21 01:51:48 -05:00
}
2014-06-16 05:37:52 -04:00
2024-03-05 21:17:56 -05:00
#
# REPO UPDATE
#
2015-02-17 12:39:08 -05:00
printf '\n%s' "$cbg_blue >> Updating darkcloud-vimconfig:$c_reset"
process_status="$(git pull origin master 2>&1)"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
error 'git pull origin master' 'Git failed to sync the repo' "$process_status"
2014-06-16 05:37:52 -04:00
exit 1
2015-02-17 12:39:08 -05:00
fi
2014-06-17 08:19:40 -04:00
2024-03-05 21:17:56 -05:00
#
# SUBMODULE UPDATE
#
2015-02-17 12:39:08 -05:00
printf '\n%s\n' "$cbg_blue >> Updating plugin submodules >> $c_reset"
printf '%s' "$cbg_blue $c_reset$cbg_yellow + Updating plugin URLs:$c_reset"
process_status="$(git submodule sync 2>&1)"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
error 'git submodule sync' 'Git failed to sync the submodules' "$process_status"
fi
2014-06-16 05:37:52 -04:00
2014-06-17 08:19:40 -04:00
# update each submodule to the new head and run 'git fetch --all'
2015-02-17 12:39:08 -05:00
printf '%s' "$cbg_blue $c_reset$cbg_yellow + Fetching updates:$c_reset"
2016-09-06 12:24:56 -04:00
git submodule foreach git reset --hard >/dev/null 2>&1
2015-02-17 12:39:08 -05:00
process_status="$(git submodule foreach git fetch --all 2>&1)"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
process_status=$(git submodule update --init --recursive 2>&1)
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
error 'git submodule update --init --recursive' 'Git failed to update the submodules' "$process_status"
fi
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
error 'git submodule foreach git fetch --all' "Git failed to fetch the submodules from their respective remotes" "$process_status"
fi
2014-05-05 08:57:38 -04:00
2014-06-16 05:37:52 -04:00
# clean plugin directories and remove plugins no longer in the repo
2015-02-17 12:39:08 -05:00
printf '\n%s\n' "$cbg_blue >> Clean plugin directories >> $c_reset"
printf '%s' "$cbg_blue $c_reset$cbg_yellow + Remove untracked files:$c_reset"
process_status="$(git submodule foreach git clean -dxf 2>&1)"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
else
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
error 'git submodule foreach git clean -dxf' 'Git failed to remove untracked files' "$process_status"
fi
2015-01-21 01:51:48 -05:00
[[ -f '.gitmodules' ]] && {
for plugin in vim/bundle/*; do
[[ -f "$plugin/.git" ]] && {
2015-02-17 12:39:08 -05:00
plugin_dirname="${plugin/*\/}"
2016-09-29 11:46:56 -04:00
2024-03-05 21:17:56 -05:00
grep 'path = ' .gitmodules | grep -oe '[^\/]*$' | grep -qe "^$plugin_dirname$" || {
2015-02-17 12:39:08 -05:00
[[ -z "$first_found" ]] && {
first_found=1
printf '%s\n' "$cbg_blue $c_reset$cbg_yellow + Removing old plugins: $c_reset"
2015-01-21 02:17:09 -05:00
}
2016-09-29 11:46:56 -04:00
2015-02-17 12:39:08 -05:00
process_status="$(rm -rf "${plugin:?}")"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2016-03-06 20:29:54 -05:00
printf '%s\n' "$cbg_blue $c_reset$cbg_yellow = $cfg_white_bold$plugin$c_reset"
2015-02-17 12:39:08 -05:00
else
error "rm -rf $plugin" "Folder couldn't be deleted" "$process_status"
2014-06-16 05:37:52 -04:00
exit 1
2015-02-17 12:39:08 -05:00
fi
2015-01-21 01:51:48 -05:00
}
}
done
2016-09-29 11:46:56 -04:00
2015-02-17 12:39:08 -05:00
printf '\n'
2015-01-21 01:51:48 -05:00
}
2014-06-17 08:19:40 -04:00
2024-03-05 21:17:56 -05:00
#
# USER PLUGIN UPDATE
#
2015-02-17 12:39:08 -05:00
[[ -d vim/bundle.user ]] && find vim/bundle.user -mindepth 3 -maxdepth 3 -name config | grep -q '.git/config' && {
printf '%s\n' "$cbg_blue >> Updating user plugins >> $c_reset"
2018-03-11 22:55:51 -04:00
pushd 'vim/bundle.user' >/dev/null || exit
2016-09-29 11:46:56 -04:00
2015-01-21 01:51:48 -05:00
for plugin in *; do
[[ -d "$plugin/.git" ]] && {
2018-03-11 22:55:51 -04:00
pushd "$plugin" >/dev/null || exit
2015-02-17 12:39:08 -05:00
printf '%s' "$cbg_blue $c_reset$cbg_yellow + Updating 'vim/bundle.user/$plugin':$c_reset"
2021-02-02 00:29:13 -05:00
process_status="$(git pull 2>&1)"
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
if ! grep -q "Already up-to-date" <<< "$process_status"; then
2015-02-17 12:53:32 -05:00
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
2015-02-17 12:39:08 -05:00
else
printf '%s\n' "$cfg_white_bold UP TO DATE $c_reset"
fi
else
2021-02-02 00:29:13 -05:00
error 'git pull' "Failed pulling changes for $plugin" "$process_status"
2015-02-17 12:39:08 -05:00
fi
2016-09-29 11:46:56 -04:00
2018-03-11 22:55:51 -04:00
popd >/dev/null || exit
2015-01-21 01:51:48 -05:00
}
done
2016-09-29 11:46:56 -04:00
2018-03-11 22:55:51 -04:00
popd >/dev/null || exit
2015-02-17 12:39:08 -05:00
printf '\n'
2015-01-21 01:51:48 -05:00
}
2014-06-17 08:19:40 -04:00
2024-03-05 21:17:56 -05:00
#
# GENERATE PLUGIN HELP
#
2018-03-16 14:29:37 -04:00
type -P vim >/dev/null && {
2015-02-17 12:39:08 -05:00
printf '%s' "$cbg_blue >> Generating plugin help:$c_reset"
2023-08-22 21:13:52 -04:00
$timeout_command --preserve-status --foreground 1m vim -u ./vimrc -c 'Helptags|qa!'
2016-09-29 11:46:56 -04:00
2015-03-14 02:22:25 -04:00
if (( ! $? )); then
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cfg_green_bold SUCCESS! $c_reset"
else
2014-06-17 08:19:40 -04:00
reset -I
2015-02-17 12:39:08 -05:00
printf '%s\n' "$cfg_red_bold FAIL! $c_reset"
2023-08-22 21:13:52 -04:00
error "vim -u './vimrc' -c 'Helptags|qa!'" 'Generating helpdocs for the submodules failed'
fi
}
2024-03-05 21:17:56 -05:00
#
# FINISH
#
2015-01-21 01:51:48 -05:00
2015-02-17 12:39:08 -05:00
printf '\n%s\n\n' "$cbg_black ~~~ Update Complete ~~~ $c_reset"