Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
backport ensure, and fix order of files when finding kakoune scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyorst committed Nov 5, 2018
1 parent 98defec commit b3801d2
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions rc/plug.kak
Expand Up @@ -53,16 +53,18 @@ declare-option -docstring \
"enable or disable messages about per plugin load time to profile configuration" \
bool plug_profiler true

declare-option -docstring \
"always ensure sthat all plugins are installed" \
bool plug_always_ensure false

hook global WinSetOption filetype=kak %{ try %{
add-highlighter window/plug regex \bplug\b\h+((?=")|(?=')|(?=%)|(?=\w)) 0:keyword
add-highlighter window/plug_do regex \bdo\b\h+((?=")|(?=')|(?=%)|(?=\w)) 0:keyword
add-highlighter window/plug_noload regex \bnoload\b 0:attribute
add-highlighter window/plug_keywords regex \b(plug|do)\b\h+((?=")|(?=')|(?=%)|(?=\w)) 0:keyword
add-highlighter window/plug_attributes regex \b(noload|ensure)\b 0:attribute
}}

hook global WinSetOption filetype=(?!kak).* %{ try %{
remove-highlighter window/plug
remove-highlighter window/plug_do
remove-highlighter window/plug_noload
remove-highlighter window/plug_keywords
remove-highlighter window/plug_attributes
}}

define-command -override -docstring \
Expand All @@ -74,9 +76,10 @@ plug -params 1.. -shell-script-candidates %{ ls -1 $(eval echo $kak_opt_plug_ins
start=$(expr $(date +%s%N) / 10000000)
plugin=$1; shift
noload=
ensure=
state=
loaded=$(eval echo $kak_opt_plug_loaded_plugins)
if [ ! -z "$loaded" ] && [ -z "${loaded##*$plugin*}" ]; then
if [ -n "$loaded" ] && [ -z "${loaded##*$plugin*}" ]; then
echo "echo -markup %{{Information}${plugin##*/} already loaded}"
exit
fi
Expand All @@ -92,6 +95,9 @@ plug -params 1.. -shell-script-candidates %{ ls -1 $(eval echo $kak_opt_plug_ins
plug_opt=$(echo "${plugin##*/}" | sed 's:[^a-zA-Z0-9_]:_:g;')
echo "set-option -add global plug_post_hooks %{$plug_opt:$1┆}"
shift ;;
"ensure")
shift;
ensure=1 ;;
*)
;;
esac
Expand All @@ -103,28 +109,33 @@ plug -params 1.. -shell-script-candidates %{ ls -1 $(eval echo $kak_opt_plug_ins
if [ -d $(eval echo $kak_opt_plug_install_dir) ]; then
if [ -d $(eval echo $kak_opt_plug_install_dir/"${plugin##*/}") ]; then
if [ ! -z $branch ]; then
if [ -n "$branch" ]; then
(cd $(eval echo $kak_opt_plug_install_dir/"${plugin##*/}"); git checkout $branch >/dev/null 2>&1)
fi
if [ -z $noload ]; then
for file in $(find -L $(eval echo $kak_opt_plug_install_dir/"${plugin##*/}") -type f -name '*.kak'); do
if [ -z "$noload" ]; then
for file in $(find -L $(eval echo $kak_opt_plug_install_dir/"${plugin##*/}") -type f -name '*.kak' | awk -F/ '{print NF-1, $F}' | sort -n | cut -d' ' -f2); do
echo source "$file"
wait
done
fi
if [ -z "${kak_opt_configurations##*$plug_conf*}" ]; then
if [ ! -z $noload ]; then
if [ -n "$noload" ]; then
state=" (configuration)"
noload=
fi
echo "plug-configure $plugin"
fi
echo "set-option -add global plug_loaded_plugins %{$plugin }"
else
exit
if [ -n "$ensure" ] || [ "$kak_opt_plug_always_ensure" = "true" ]; then
echo "evaluate-commands -client ${kak_client:-client0} plug-install $plugin" | kak -p ${kak_session}
else
exit
fi
fi
fi
if [ -z $noload ]; then
if [ -z "$noload" ]; then
end=$(expr $(date +%s%N) / 10000000)
message="loaded ${plugin##*/}$state in"
echo "plug-elapsed '$start' '$end' '$message'"
Expand All @@ -148,7 +159,7 @@ plug-install -params ..1 %{
mkdir -p $(eval echo $kak_opt_plug_install_dir)
fi
if [ ! -z $plugin ]; then
if [ -n "$plugin" ]; then
case $plugin in
http*|git*)
git="git clone $plugin --depth 1" ;;
Expand Down Expand Up @@ -191,7 +202,6 @@ plug-install -params ..1 %{
wait
rm -rf $jobs
fi
printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}Done installing plugins'" | kak -p ${kak_session}
) >/dev/null 2>&1 < /dev/null & }
}

Expand All @@ -207,9 +217,8 @@ plug-update -params ..1 -shell-script-candidates %{ echo $kak_opt_plug_plugins |
while ! mkdir $(eval echo "$kak_opt_plug_install_dir/.plug.kaklock") 2>/dev/null; do sleep 1; done
trap 'rmdir $(eval echo "$kak_opt_plug_install_dir/.plug.kaklock")' EXIT
if [ ! -z $plugin ]; then
if [ -n "$plugini" ]; then
if [ -d $(eval echo $kak_opt_plug_install_dir/"${plugin##*/}") ]; then
printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}Updating $plugin'" | kak -p ${kak_session}
(
cd $(eval echo $kak_opt_plug_install_dir/"${plugin##*/}") && rev=$(git rev-parse HEAD) && git pull -q
if [ $rev != $(git rev-parse HEAD) ]; then
Expand Down Expand Up @@ -257,7 +266,7 @@ plug-clean -params ..1 -shell-script-candidates %{ ls -1 $(eval echo $kak_opt_pl
while ! mkdir $(eval echo "$kak_opt_plug_install_dir/.plug.kaklock") 2>/dev/null; do sleep 1; done
trap 'rmdir $(eval echo "$kak_opt_plug_install_dir/.plug.kaklock")' EXIT
if [ ! -z $plugin ]; then
if [ -n "$plugin" ]; then
if [ -d $(eval echo $kak_opt_plug_install_dir/"${plugin##*/}") ]; then
(cd $(eval echo $kak_opt_plug_install_dir) && rm -rf "${plugin##*/}")
printf %s\\n "evaluate-commands -client $kak_client echo -debug 'removed ${plugin##*/}'" | kak -p ${kak_session}
Expand Down Expand Up @@ -319,7 +328,7 @@ plug-eval-hooks -params 1 %{
break
fi
done
if [ -z $error ]; then
if [ -z "$error" ]; then
printf %s\\n "evaluate-commands -client $kak_client echo -debug %{finished post-update hooks for ${1##*/}}" | kak -p ${kak_session}
else
printf %s\\n "evaluate-commands -client $kak_client echo -debug %{error occured while evaluation of post-update hooks for ${1##*/}:}" | kak -p ${kak_session}
Expand Down

0 comments on commit b3801d2

Please sign in to comment.