diff --git a/base/core/core.zsh b/base/core/core.zsh index 78cf92de..b25e1ae8 100644 --- a/base/core/core.zsh +++ b/base/core/core.zsh @@ -244,8 +244,10 @@ __zplug::core::core::variable() "defer_3_plugin" "$ZPLUG_CACHE_DIR/defer_3_plugin.zsh" ) - typeset -gx -a _zplug_checkout_locks - _zplug_checkout_locks=() + typeset -gx -A _zplug_lock + _zplug_lock=( + "job" "$ZPLUG_HOME/log/job.lock" + ) if (( $+ZPLUG_SHALLOW )); then __zplug::io::print::f \ diff --git a/base/core/load.zsh b/base/core/load.zsh index 3c78e33d..122ec382 100644 --- a/base/core/load.zsh +++ b/base/core/load.zsh @@ -13,7 +13,7 @@ __zplug::core::load::from_cache() zstyle -s ':zplug:core:load' 'verbose' is_verbose # Default - setopt monitor + # setopt monitor __zplug::core::cache::update diff --git a/base/job/handle.zsh b/base/job/handle.zsh index 7ff33e77..ad8e5897 100644 --- a/base/job/handle.zsh +++ b/base/job/handle.zsh @@ -4,6 +4,8 @@ __zplug::job::handle::flock() local is_escape=false local -a args + local file contents + while (( $#argv > 0 )) do case "$argv[1]" in @@ -13,7 +15,7 @@ __zplug::job::handle::flock() -*|--*) ;; *) - args+=("$argv[1]") + args+=( "$argv[1]" ) ;; esac shift @@ -23,7 +25,8 @@ __zplug::job::handle::flock() return 1 fi - local file="$args[1]" contents="$args[2]" + file="$args[1]" + contents="$args[2]" # TODO: Temporary fix to solve #334 if [[ ! -f $file ]]; then @@ -53,11 +56,10 @@ __zplug::job::handle::flock() # Save the status code with LTSV if $is_escape; then - __zplug::io::print::f "${(q)contents}\n" + print -r "$contents" >>|"$file" else - __zplug::io::print::f "$contents\n" + print "$contents" >>|"$file" fi >>|"$file" - ) } @@ -246,6 +248,7 @@ __zplug::job::handle::hook() } & hook_pids[$repo]=$! # Run the timeout process in background { + touch "$_zplug_lock[job]" # kill the process for hook-build after sleeping # during the number of seconds that has been set as a timeout sleep "$timeout" @@ -257,6 +260,7 @@ __zplug::job::handle::hook() builtin printf "$repo\n" >>|"$_zplug_build_log[timeout]" builtin printf "$repo\n" >>|"$_zplug_build_log[rollback]" fi + rm -f "$_zplug_lock[job]" } & fi diff --git a/base/job/polling.zsh b/base/job/polling.zsh index 6ff136f1..a9cea49b 100644 --- a/base/job/polling.zsh +++ b/base/job/polling.zsh @@ -1,10 +1,17 @@ -#export PERIOD=10 +export PERIOD=30 -__zplug::job::polling::finalizer() +__zplug::job::polling::periodic() { - # Display the corsor - tput cnorm - # TODO + if [[ -f $_zplug_lock[job] ]]; then + setopt nomonitor + else + if [[ -o monitor ]]; then + return 0 + fi + if setopt monitor; then + __zplug::log::write::info "turn monitor on" + fi + fi } -#add-zsh-hook periodic __zplug::job::polling::finalizer +add-zsh-hook periodic __zplug::job::polling::periodic diff --git a/base/log/capture.zsh b/base/log/capture.zsh index bd4fdacf..40086eff 100644 --- a/base/log/capture.zsh +++ b/base/log/capture.zsh @@ -8,7 +8,7 @@ __zplug::log::capture::error() __zplug::job::handle::flock --escape \ "$_zplug_log[trace]" \ - "$(__zplug::log::format::with_json --level "ERROR" --message "$message" "${argv[@]:-}")" + "$(__zplug::log::format::with_json "ERROR" "$message")" } __zplug::log::capture::debug() @@ -21,5 +21,18 @@ __zplug::log::capture::debug() __zplug::job::handle::flock --escape \ "$_zplug_log[trace]" \ - "$(__zplug::log::format::with_json --level "DEBUG" --message "$message" "${argv[@]:-}")" + "$(__zplug::log::format::with_json "DEBUG" "$message")" +} + +__zplug::log::capture::info() +{ + local message="$(<&0)" + + if [[ -z $message ]]; then + return 0 + fi + + __zplug::job::handle::flock --escape \ + "$_zplug_log[trace]" \ + "$(__zplug::log::format::with_json "INFO" "$message")" } diff --git a/base/log/format.zsh b/base/log/format.zsh index a6414a93..ac6ec456 100644 --- a/base/log/format.zsh +++ b/base/log/format.zsh @@ -1,48 +1,32 @@ __zplug::log::format::with_json() { local -i i=1 - local level="${1:-"INFO"}" message + local level="${1:-"INFO"}" message="$2" local is_message_json=false - while (( $#argv > 0 )) - do - case "$argv[1]" in - --message) - message="$argv[2]"; shift - ;; - --level) - level="$argv[2]"; shift - ;; - --message-json) - is_message_json=true - ;; - esac - shift - done - # Spit out to JSON - printf '{' - printf '"pid":%d,' "$$" - printf '"shlvl":%d,' "$SHLVL" - printf '"level":"%s",' "$level" - printf '"dir":"%s",' "$PWD" - printf '"message":' + builtin printf '{' + builtin printf '"pid":%d,' "$$" + builtin printf '"shlvl":%d,' "$SHLVL" + builtin printf '"level":"%s",' "$level" + builtin printf '"dir":"%s",' "$PWD" + builtin printf '"message":' if $is_message_json; then - printf "$message" + builtin printf "$message" else - printf "$message" \ + builtin printf "$message" \ | __zplug::utils::ansi::remove \ | __zplug::utils::shell::json_escape \ | tr -d '\n' fi - printf ',' - printf '"trace":[' + builtin printf ',' + builtin printf '"trace":[' for ((i = 1; i < $#functrace; i++)) do - printf '"%s",' "$functrace[$i]" + builtin printf '"%s",' "$functrace[$i]" done - printf '"%s"' "$functrace[$#functrace]" - printf "]," - printf '"date":"%s"' "$(strftime "%FT%T%z" $EPOCHSECONDS)" - printf "}\n" + builtin printf '"%s"' "$functrace[$#functrace]" + builtin printf "]," + builtin printf '"date":"%s"' "$(strftime "%FT%T%z" $EPOCHSECONDS)" + builtin printf "}\n" } diff --git a/base/log/print.zsh b/base/log/print.zsh index df25a33b..56d20dd9 100644 --- a/base/log/print.zsh +++ b/base/log/print.zsh @@ -8,6 +8,16 @@ __zplug::log::print::error() "$argv[2,-1]" } +__zplug::log::print::debug() +{ + # No problem since this function ignores + # unrelated arguments passed + __zplug::log::format::with_json \ + --level "DEBUG" \ + --message "$argv[1]" \ + "$argv[2,-1]" +} + __zplug::log::print::info() { # No problem since this function ignores diff --git a/base/log/write.zsh b/base/log/write.zsh index b4373093..f94eb7cb 100644 --- a/base/log/write.zsh +++ b/base/log/write.zsh @@ -2,12 +2,19 @@ __zplug::log::write::error() { __zplug::job::handle::flock --escape \ "$_zplug_log[trace]" \ - "$(__zplug::log::print::error "${argv[@]:-}")" + "$(__zplug::log::format::with_json "ERROR" "$argv[@]")" +} + +__zplug::log::write::debug() +{ + __zplug::job::handle::flock --escape \ + "$_zplug_log[trace]" \ + "$(__zplug::log::format::with_json "DEBUG" "$argv[@]")" } __zplug::log::write::info() { __zplug::job::handle::flock --escape \ "$_zplug_log[trace]" \ - "$(__zplug::log::print::info "${argv[@]:-}")" + "$(__zplug::log::format::with_json "INFO" "$argv[@]")" }