From 89c01dc235979644601f127c222c04ae0f912490 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Sat, 20 Feb 2016 09:57:51 +0900 Subject: [PATCH] Add instrumentation using fishery/debug. --- functions/__fisher_deps_install.fish | 2 ++ functions/__fisher_file_remove.fish | 2 ++ functions/__fisher_gist_to_name.fish | 2 ++ functions/__fisher_index_update.fish | 8 +++++-- functions/__fisher_key_bindings_disable.fish | 2 ++ functions/__fisher_key_bindings_enable.fish | 2 ++ .../__fisher_key_bindings_update_user.fish | 1 + functions/__fisher_path_make.fish | 4 ++++ functions/__fisher_path_update.fish | 4 +++- functions/__fisher_plugin_disable.fish | 4 ++++ functions/__fisher_plugin_enable.fish | 8 +++++++ functions/__fisher_plugin_link.fish | 2 ++ functions/__fisher_plugin_source.fish | 2 ++ functions/__fisher_plugin_unlink.fish | 3 +++ functions/__fisher_plugin_validate.fish | 1 - functions/__fisher_plugin_walk.fish | 9 ++++++++ functions/__fisher_prompt_reset.fish | 4 ++++ functions/debug.fish | 2 ++ functions/fisher_install.fish | 23 ++++++++++++++++--- functions/fisher_search.fish | 2 ++ functions/fisher_uninstall.fish | 12 ++++++++++ functions/fisher_update.fish | 13 +++++++++-- test/helpers/config-mock.fish | 11 +++++++++ 23 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 functions/debug.fish diff --git a/functions/__fisher_deps_install.fish b/functions/__fisher_deps_install.fish index 65f2cce..5e80ef7 100644 --- a/functions/__fisher_deps_install.fish +++ b/functions/__fisher_deps_install.fish @@ -1,4 +1,6 @@ function __fisher_deps_install -a path + debug "Install dependencies in '%s'" "$path" + for file in $path/{fishfile,bundle} if test -s $file fisher_install < $file | sed -En 's/^.+([0-9]+) plugin\/s.*/\1/p' diff --git a/functions/__fisher_file_remove.fish b/functions/__fisher_file_remove.fish index a052762..b4ad3f3 100644 --- a/functions/__fisher_file_remove.fish +++ b/functions/__fisher_file_remove.fish @@ -6,6 +6,8 @@ function __fisher_file_remove -a plugin file set pattern "/^$pattern\$/d" end + debug "Remove '%s' from fishfile '%s'" "$plugin" "$file" + sed -E "$pattern" < $file > $file.tmp command mv $file.tmp $file diff --git a/functions/__fisher_gist_to_name.fish b/functions/__fisher_gist_to_name.fish index da9733e..c04bc89 100644 --- a/functions/__fisher_gist_to_name.fish +++ b/functions/__fisher_gist_to_name.fish @@ -1,6 +1,8 @@ function __fisher_gist_to_name -a url set -l id (printf "%s\n" "$url" | sed 's|.*/||') + debug "Get Gist information '%s'" $url + set -l name ( spin "curl -Ss https://api.github.com/gists/$id" | awk ' diff --git a/functions/__fisher_index_update.fish b/functions/__fisher_index_update.fish index b1eac20..a432e19 100644 --- a/functions/__fisher_index_update.fish +++ b/functions/__fisher_index_update.fish @@ -7,20 +7,24 @@ function __fisher_index_update -a timeout end end + debug "Update index with timeout '%.1f'" $timeout + set -l url $fisher_index set -l index $fisher_cache/.index.tmp if test -z "$url" - # Force the server to return the latest copy of the index using a fake query string. - set url https://raw.githubusercontent.com/fisherman/fisher-index/master/index\?(date +%s) end if not curl --max-time $timeout -sS "$url" > $index + debug "Update index fail" + command rm -f $index return 1 end + debug "Update index complete" + command mv -f $index $fisher_cache/.index end diff --git a/functions/__fisher_key_bindings_disable.fish b/functions/__fisher_key_bindings_disable.fish index 4720a04..1e987fc 100644 --- a/functions/__fisher_key_bindings_disable.fish +++ b/functions/__fisher_key_bindings_disable.fish @@ -10,6 +10,8 @@ function __fisher_key_bindings_disable -a plugin user_key_bindings command mv -f $fisher_binds.tmp $fisher_binds if test ! -s $fisher_binds + debug "Remove fisherman key bindings '%s'" "$user_key_bindings" + sed -i.tmp '/__fisher_key_bindings/d' $user_key_bindings command rm -f $user_key_bindings.tmp end diff --git a/functions/__fisher_key_bindings_enable.fish b/functions/__fisher_key_bindings_enable.fish index 0cae247..fc20200 100644 --- a/functions/__fisher_key_bindings_enable.fish +++ b/functions/__fisher_key_bindings_enable.fish @@ -12,6 +12,8 @@ function __fisher_key_bindings_enable -a plugin user_key_bindings source $user_key_bindings end + debug "Add fisherman key bindings '%s'" "$user_key_bindings" + functions fish_user_key_bindings \ | __fisher_key_bindings_update_user > $user_key_bindings end diff --git a/functions/__fisher_key_bindings_update_user.fish b/functions/__fisher_key_bindings_update_user.fish index f4eaacf..8971262 100644 --- a/functions/__fisher_key_bindings_update_user.fish +++ b/functions/__fisher_key_bindings_update_user.fish @@ -5,5 +5,6 @@ function __fisher_key_bindings_update_user } $0 !~ "^[ \t]*" src { print } + ' | fish_indent end diff --git a/functions/__fisher_path_make.fish b/functions/__fisher_path_make.fish index 0b42bf8..a152a5b 100644 --- a/functions/__fisher_path_make.fish +++ b/functions/__fisher_path_make.fish @@ -3,11 +3,15 @@ function __fisher_path_make -a path return end + debug "Makefile '%s'" "$path/Makefile" + pushd $path set -e argv[1] if not make $argv + debug "Make fail '%s'" "$argv" + popd return 1 end diff --git a/functions/__fisher_path_update.fish b/functions/__fisher_path_update.fish index c6d1f08..72e8eee 100644 --- a/functions/__fisher_path_update.fish +++ b/functions/__fisher_path_update.fish @@ -1,8 +1,10 @@ function __fisher_path_update -a path pushd $path + debug "Update repository '%s'" "$path" + git checkout master --quiet ^ /dev/null - git pull --rebase origin master --quiet + git pull --rebase origin master --quiet popd end diff --git a/functions/__fisher_plugin_disable.fish b/functions/__fisher_plugin_disable.fish index f9d5bf7..5e1079c 100644 --- a/functions/__fisher_plugin_disable.fish +++ b/functions/__fisher_plugin_disable.fish @@ -2,6 +2,8 @@ function __fisher_plugin_disable -a plugin path option __fisher_plugin_walk "$plugin" "$path" | while read -l class source target name switch "$class" case --bind + debug "Disable key bindings '%s'" $plugin + __fisher_key_bindings_disable $plugin (__fisher_xdg --config )/fish/functions/fish_user_key_bindings.fish @@ -18,6 +20,8 @@ function __fisher_plugin_disable -a plugin path option end if test -s $fisher_file + debug "Remove '%s' from fishfile" "$plugin" + __fisher_file_remove ( if not fisher_search --name=$plugin --name --index=$fisher_cache/.index __fisher_url_from_path $path diff --git a/functions/__fisher_plugin_enable.fish b/functions/__fisher_plugin_enable.fish index f1c6a8f..6f7c143 100644 --- a/functions/__fisher_plugin_enable.fish +++ b/functions/__fisher_plugin_enable.fish @@ -2,6 +2,8 @@ function __fisher_plugin_enable -a plugin path if __fisher_path_is_prompt $path if test ! -z "$fisher_prompt" + debug "Disable current prompt to install '%s'" $plugin + # Why do we need to disable a prompt before installing another? I thought # one prompt would override the other? @@ -33,6 +35,8 @@ function __fisher_plugin_enable -a plugin path __fisher_plugin_walk "$plugin" "$path" | while read -l class source target __unused switch "$class" case --bind + debug "Enable key bindings in '%s'" $source + __fisher_key_bindings_enable $plugin (__fisher_xdg --config )/fish/functions/fish_user_key_bindings.fish < $source @@ -58,9 +62,13 @@ function __fisher_plugin_enable -a plugin path if test -s $fisher_file if __fisher_file_contains "$item" --quiet $fisher_file + debug "Skip '%s' already in fishfile" $item + return end end + debug "Adding '%s' to fishfile" $item + printf "%s\n" $item >> $fisher_file end diff --git a/functions/__fisher_plugin_link.fish b/functions/__fisher_plugin_link.fish index 7795269..4ba532d 100644 --- a/functions/__fisher_plugin_link.fish +++ b/functions/__fisher_plugin_link.fish @@ -1,3 +1,5 @@ function __fisher_plugin_link -a options source target + debug "Link '%s'" $target + command ln $options $source $target end diff --git a/functions/__fisher_plugin_source.fish b/functions/__fisher_plugin_source.fish index a47a71f..04884de 100644 --- a/functions/__fisher_plugin_source.fish +++ b/functions/__fisher_plugin_source.fish @@ -1,3 +1,5 @@ function __fisher_plugin_source -a plugin file + debug "Source '%s'" $file + source "$file" ^ /dev/null end diff --git a/functions/__fisher_plugin_unlink.fish b/functions/__fisher_plugin_unlink.fish index d9c2ca9..bf048f2 100644 --- a/functions/__fisher_plugin_unlink.fish +++ b/functions/__fisher_plugin_unlink.fish @@ -1,4 +1,7 @@ function __fisher_plugin_unlink -a name file + debug "Unlink '%s'" $file command rm -f $file + + debug "Erase function '%s'" $name functions -e $name end diff --git a/functions/__fisher_plugin_validate.fish b/functions/__fisher_plugin_validate.fish index b138885..0160ddf 100644 --- a/functions/__fisher_plugin_validate.fish +++ b/functions/__fisher_plugin_validate.fish @@ -13,7 +13,6 @@ function __fisher_plugin_validate -a plugin printf "%s\n" $plugin case \* - printf "$PWD/%s/%s" (dirname $plugin) (basename $plugin) end | sed -E 's|[./]*$||; s|/([\./])/+|/|g' diff --git a/functions/__fisher_plugin_walk.fish b/functions/__fisher_plugin_walk.fish index 1628e21..1d68527 100644 --- a/functions/__fisher_plugin_walk.fish +++ b/functions/__fisher_plugin_walk.fish @@ -1,8 +1,12 @@ function __fisher_plugin_walk -a plugin path + debug "Walk tree in '%s'" "$path" + for file in $path/{*,{conf.d,modules}/*,functions/**}.{fish,load} $path/completions/*.fish set -l name (basename $file .fish) set -l base $name.fish + debug "File '%s'" $file + switch $file case \*/{fish_user_,}key_bindings.fish printf "%s %s %s\n" --bind $file @@ -17,6 +21,7 @@ function __fisher_plugin_walk -a plugin path switch "$base" case \*$plugin\* case \* + debug "Rename '%s' to '%s'" $plugin $plugin.$base set base $plugin.$base end @@ -30,11 +35,15 @@ function __fisher_plugin_walk -a plugin path for file in $path/{functions/,}*.{py,rb,php,pl,awk,sed} set -l base (basename $file) + debug "Script file '%s'" $file + printf "%s %s %s\n" -- $file functions/$base end for n in (seq 9) for file in $path/man/man$n/*.$n + debug "Manual page '%s'" $file + printf "%s %s %s\n" --man $file man/man$n/(basename $file) end end diff --git a/functions/__fisher_prompt_reset.fish b/functions/__fisher_prompt_reset.fish index 162586c..1e2f498 100644 --- a/functions/__fisher_prompt_reset.fish +++ b/functions/__fisher_prompt_reset.fish @@ -1,4 +1,6 @@ function __fisher_prompt_reset + debug "Reset prompt '%s'" "$fisher_prompt" + set -U fisher_prompt # To reset the prompt, remove any data in fisher_prompt and source any existing @@ -10,6 +12,8 @@ function __fisher_prompt_reset for prompt in $argv/functions/fish_prompt.fish if test -s $prompt + debug "Default prompt '%s'" $prompt + source $prompt return end diff --git a/functions/debug.fish b/functions/debug.fish new file mode 100644 index 0000000..525f8e1 --- /dev/null +++ b/functions/debug.fish @@ -0,0 +1,2 @@ +function debug +end diff --git a/functions/fisher_install.fish b/functions/fisher_install.fish index 13c9b21..6f01272 100644 --- a/functions/fisher_install.fish +++ b/functions/fisher_install.fish @@ -39,12 +39,12 @@ function fisher_install -d "Install Plugins" set -l skipped if set -q plugins[1] - printf "%s\n" $plugins else __fisher_file end | while read -l item + debug "Validate '%s'" $item if not set item (__fisher_plugin_validate $item) printf "fisher: '%s' is not a valid name, path or URL.\n" $item > $stderr @@ -53,6 +53,8 @@ function fisher_install -d "Install Plugins" switch "$item" case https://gist.github.com\* + debug "Install a Gist '%s'" $item + if set -l name (__fisher_gist_to_name $item) printf "%s %s\n" $item $name else @@ -61,13 +63,19 @@ function fisher_install -d "Install Plugins" end case \*/\* + debug "Install from a URL or path '%s'" $item + printf "%s %s\n" $item (printf "%s\n" $item | __fisher_name) case \* if set -l url (fisher_search --url --name=$item --index=$fisher_cache/.index) + debug "Install '%s'" $item + printf "%s %s\n" $url $item else if test -d $fisher_cache/$item + debug "Install from '%s'" \$fisher_cache/$item + printf "%s %s\n" (__fisher_url_from_path $fisher_cache/$item) $item else @@ -103,10 +111,15 @@ function fisher_install -d "Install Plugins" if test ! -e $path if test -d "$url" + debug "Link '%s' to the cache" $url + command ln -sfF $url $path + else + debug "Download '%s'" $url - else if not spin "__fisher_url_clone $url $path" --error=$stderr - continue + if not spin "__fisher_url_clone $url $path" --error=$stderr + continue + end end end @@ -135,8 +148,12 @@ function fisher_install -d "Install Plugins" return 1 end + debug "Pre-reset completions and key bindings" + __fisher_complete_reset __fisher_key_bindings_reset + debug "Post-reset completions and key bindings" + printf "Aye! %d plugin/s installed in %0.fs\n" $count $time > $stdout end diff --git a/functions/fisher_search.fish b/functions/fisher_search.fish index 3d5d836..3c84079 100644 --- a/functions/fisher_search.fish +++ b/functions/fisher_search.fish @@ -87,6 +87,8 @@ function fisher_search -d "Search Plugins" end if test $fisher_last_update -gt $fisher_update_interval -o ! -f $index + debug "Update index" + if spin "__fisher_index_update" --error=/dev/null __fisher_complete_reset end diff --git a/functions/fisher_uninstall.fish b/functions/fisher_uninstall.fish index 59ca627..a6098f9 100644 --- a/functions/fisher_uninstall.fish +++ b/functions/fisher_uninstall.fish @@ -45,6 +45,8 @@ function fisher_uninstall -d "Uninstall Plugins" end | while read -l item path + debug "Validate '%s'" $item + if not set item (__fisher_plugin_validate $item) printf "fisher: '%s' is not a valid name, path or url.\n" $item > $stderr continue @@ -58,6 +60,8 @@ function fisher_uninstall -d "Uninstall Plugins" set -l name (printf "%s\n" $path | __fisher_name) + debug "Uninstall '%s' in '%s'" "$name" "$path" + if not contains -- $name (__fisher_list $fisher_file) if test -z "$option" set total (math $total - 1) @@ -78,10 +82,14 @@ function fisher_uninstall -d "Uninstall Plugins" end if __fisher_plugin_can_enable "$name" "$path" + debug "Plugin disable '%s' w/ option '%s'" "$name" "$option" + __fisher_plugin_disable "$name" "$path" "$option" end if test "$option" = force + debug "Remove path '%s'" "$path" + command rm -rf $path end @@ -101,8 +109,12 @@ function fisher_uninstall -d "Uninstall Plugins" return 1 end + debug "Pre-reset completions and key bindings" + __fisher_complete_reset __fisher_key_bindings_reset + debug "Post-reset completions and key bindings" + printf "Aye! %d plugin/s uninstalled in %0.fs\n" $count $time > $stdout end diff --git a/functions/fisher_update.fish b/functions/fisher_update.fish index 2ba0b82..3aaacbb 100644 --- a/functions/fisher_update.fish +++ b/functions/fisher_update.fish @@ -34,19 +34,22 @@ function fisher_update -d "Update Plugins/Fisherman" case self set -l time (date +%s) + debug "Update Fisherman" + printf "Updating >> Fisherman\n" > $stderr if not spin " __fisher_index_update 0 __fisher_path_update $fisher_home" --error=$stderr - ### - ### + debug "Update Fisherman fail" printf "fisher: Arrr! Could not update Fisherman.\n" > $stderr return 1 end + debug "Update Fisherman complete" + printf "Aye! Fisherman updated to version %s (%0.fs)\n" ( cat $fisher_home/VERSION) (math (date +%s) - $time) > $stderr @@ -64,6 +67,8 @@ function fisher_update -d "Update Plugins/Fisherman" end | while read -l item path + debug "Validate '%s'" $item + if not set item (__fisher_plugin_validate $item) printf "fisher: '%s' is not a valid name, path or url.\n" $item > $stderr continue @@ -89,12 +94,16 @@ function fisher_update -d "Update Plugins/Fisherman" end if test ! -L $path + debug "Update plugin '%s'" "$name" + if not spin "__fisher_path_update $path" --error=$stderr continue end end if __fisher_plugin_can_enable "$name" "$path" + debug "Install to enable '%s'" "$name" + fisher_install --quiet --force -- $name end diff --git a/test/helpers/config-mock.fish b/test/helpers/config-mock.fish index 5ea9b45..f41b284 100644 --- a/test/helpers/config-mock.fish +++ b/test/helpers/config-mock.fish @@ -1,8 +1,19 @@ # Reset Fisherman's configuration state. +if functions -q debug + functions -c debug debug_copy +end + set -g fisher_config $argv + source $fisher_home/config.fish +if functions -q debug + functions -e debug + functions -c debug_copy debug + functions -e debug_copy +end + set -U fisher_prompt set -g plugins $DIRNAME/fixtures/plugins set -g fisher_index file://$plugins/index