ea6adc5a0a3332e541a812a2da0e94c73e2102da

Author
Andrew Janke <andrew@apjanke.net>
Committer
Andrew Janke <andrew@apjanke.net>
Date

Message

Add omz_diagnostic_dump() to help with bug reports.

Diff

This diff is truncated to protect this page.

  1diff --git a/lib/diagnostics.zsh b/lib/diagnostics.zsh
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..cca13f4e4305084b731559550787aa098c3062b7
  4--- /dev/null
  5+++ b/lib/diagnostics.zsh
  6@@ -0,0 +1,280 @@
  7+# diagnostics.zsh
  8+#
  9+# Diagnostic and debugging support for oh-my-zsh
 10+
 11+# omz_diagnostic_dump()
 12+#
 13+# Author: Andrew Janke <andrew@apjanke.net>
 14+#
 15+# Usage:
 16+#
 17+# omz_diagnostic_dump [-v] [-V] [file]
 18+#
 19+# NOTE: This is a work in progress. Its interface and behavior are going to change,
 20+# and probably in non-back-compatible ways.
 21+#
 22+# Outputs a bunch of information about the state and configuration of
 23+# oh-my-zsh, zsh, and the user's system. This is intended to provide a
 24+# bunch of context for diagnosing your own or a third party's problems, and to
 25+# be suitable for posting to public bug reports.
 26+#
 27+# The output is human-readable and its format may change over time. It is not
 28+# suitable for parsing. All the output is in one single file so it can be posted
 29+# as a gist or bug comment on GitHub. GitHub doesn't support attaching tarballs
 30+# or other files to bugs; otherwise, this would probably have an option to produce
 31+# tarballs that contain copies of the config and customization files instead of
 32+# catting them all in to one file.
 33+#
 34+# This is intended to be widely portable, and run anywhere that oh-my-zsh does.
 35+# Feel free to report any portability issues as bugs.
 36+#
 37+# This is written in a defensive style so it still works (and can detect) cases when
 38+# basic functionality like echo and which have been redefined. In particular, almost
 39+# everything is invoked with "builtin" or "command", to work in the face of user 
 40+# redefinitions.
 41+#
 42+# OPTIONS
 43+#
 44+# [file]   Specifies the output file. If not given, a file in the current directory
 45+#        is selected automatically.
 46+#
 47+# -v    Increase the verbosity of the dump output. May be specified multiple times.
 48+#       Verbosity levels:
 49+#        0 - Basic info, shell state, omz configuration, git state
 50+#        1 - (default) Adds key binding info and configuration file contents
 51+#        2 - Adds zcompdump file contents
 52+#
 53+# -V    Reduce the verbosity of the dump output. May be specified multiple times.
 54+#
 55+# TODO:
 56+# * Multi-file capture
 57+# * Add automatic gist uploading
 58+# * Consider whether to move default output file location to TMPDIR. More robust
 59+#     but less user friendly.
 60+#
 61+function omz_diagnostic_dump() {
 62+  emulate -L zsh
 63+
 64+  local thisfcn=omz_diagnostic_dump
 65+  local -A opts
 66+  local opt_verbose opt_noverbose opt_outfile
 67+  local timestamp=$(date +%Y%m%d-%H%M%S)
 68+  local outfile=omz_diagdump_$timestamp.txt
 69+  builtin zparseopts -A opts -D -- "v+=opt_verbose" "V+=opt_noverbose"
 70+  local verbose n_verbose=${#opt_verbose} n_noverbose=${#opt_noverbose}
 71+  (( verbose = 1 + n_verbose - n_noverbose ))
 72+
 73+  if [[ ${#*} > 0 ]]; then
 74+    opt_outfile=$1
 75+  fi
 76+  if [[ ${#*} > 1 ]]; then
 77+    builtin echo "$thisfcn: error: too many arguments" >&2
 78+    return 1
 79+  fi
 80+  if [[ -n "$opt_outfile" ]]; then
 81+    outfile="$opt_outfile"
 82+  fi
 83+
 84+  # Always write directly to a file so terminal escape sequences are
 85+  # captured cleanly
 86+  _omz_diag_dump_one_big_text &> "$outfile"
 87+  if [[ $? != 0 ]]; then
 88+    builtin echo "$thisfcn: error while creating diagnostic dump; see $outfile for details"
 89+  fi
 90+
 91+  builtin echo
 92+  builtin echo Diagnostic dump file created at: "$outfile"
 93+  builtin echo
 94+  builtin echo To share this with OMZ developers, post it as a gist on GitHub 
 95+  builtin echo at "https://gist.github.com" and share the link to the gist.
 96+  builtin echo
 97+  builtin echo "WARNING: This dump file contains all your zsh and omz configuration files,"
 98+  builtin echo "so don't share it publicly if there's sensitive information in them."
 99+  builtin echo
100+
101+}
102+
103+function _omz_diag_dump_one_big_text() {
104+  local program programs progfile md5
105+