0bb3e0188ca154b7b362cbf7723dee938a26b2b9

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #3940 from apjanke/diagnostic-dump-function

Add omz_diagnostic_dump() to help with bug reporting

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..afc33829b01c0a09dc0633a21fbfee906c5d3116
  4--- /dev/null
  5+++ b/lib/diagnostics.zsh
  6@@ -0,0 +1,335 @@
  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+  builtin echo "Generating diagnostic dump; please be patient..."
 65+  
 66+  local thisfcn=omz_diagnostic_dump
 67+  local -A opts
 68+  local opt_verbose opt_noverbose opt_outfile
 69+  local timestamp=$(date +%Y%m%d-%H%M%S)
 70+  local outfile=omz_diagdump_$timestamp.txt
 71+  builtin zparseopts -A opts -D -- "v+=opt_verbose" "V+=opt_noverbose"
 72+  local verbose n_verbose=${#opt_verbose} n_noverbose=${#opt_noverbose}
 73+  (( verbose = 1 + n_verbose - n_noverbose ))
 74+
 75+  if [[ ${#*} > 0 ]]; then
 76+    opt_outfile=$1
 77+  fi
 78+  if [[ ${#*} > 1 ]]; then
 79+    builtin echo "$thisfcn: error: too many arguments" >&2
 80+    return 1
 81+  fi
 82+  if [[ -n "$opt_outfile" ]]; then
 83+    outfile="$opt_outfile"
 84+  fi
 85+
 86+  # Always write directly to a file so terminal escape sequences are
 87+  # captured cleanly
 88+  _omz_diag_dump_one_big_text &> "$outfile"
 89+  if [[ $? != 0 ]]; then
 90+    builtin echo "$thisfcn: error while creating diagnostic dump; see $outfile for details"
 91+  fi
 92+
 93+  builtin echo
 94+  builtin echo Diagnostic dump file created at: "$outfile"
 95+  builtin echo
 96+  builtin echo To share this with OMZ developers, post it as a gist on GitHub 
 97+  builtin echo at "https://gist.github.com" and share the link to the gist.
 98+  builtin echo
 99+  builtin echo "WARNING: This dump file contains all your zsh and omz configuration files,"
100+  builtin echo "so don't share it publicly if there's sensitive information in them."
101+  builtin echo
102+
103+}
104+
105+function _omz_diag_dump_one_big_text() {