zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: git --pretty completion, and (new) completion for npm
@ 2011-03-14  6:38 Johan Sundström
  2011-03-20 10:35 ` Frank Terbeck
  0 siblings, 1 reply; 6+ messages in thread
From: Johan Sundström @ 2011-03-14  6:38 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 793 bytes --]

I just realized I have been using zsh for about fifteen years, and that the
sane(r) completion system of zsh 3.1 has been around for more than ten. Both
together must have saved me months of work and typing on aggregate, by
now. Time for some celebration! :-)

I took to adding documented completion for to the git completer for syntax
that is impossible to remember and hard to find in the man page; git log
--pretty (and whichever other commands support --pretty / --format) now
covers the whole lot except %w, which seemed like it would need a whole
little state machine in itself.

Also, a Completion/Unix/Command/_npm (the node package manager) completer
that delegates entirely to npm's built-in support.

Cheers!

-- 
 / Johan Sundström, http://ecmanaut.blogspot.com/

[-- Attachment #1.2: Type: text/html, Size: 929 bytes --]

[-- Attachment #2: _git-pretty.patch --]
[-- Type: application/octet-stream, Size: 5036 bytes --]

From 50fe32aa4cdffad0054a6b8cb058b1d2e5361d2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Johan=20Sundstr=C3=B6m?= <oyasumi@gmail.com>
Date: Sun, 13 Mar 2011 13:10:03 -0700
Subject: [PATCH 1/2] make git --pretty completion list git config pretty.NAME defs, and all fields but %w

---
 Completion/Unix/Command/_git |   85 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 77 insertions(+), 8 deletions(-)

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index bf22a3c..ca1dd5d 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5543,23 +5543,92 @@ __git_setup_diff_options () {
     '--output[undocumented]:undocumented')
 }
 
+(( $+functions[__git_setup_pretty_aliases] )) ||
+__git_setup_pretty_aliases () {
+  local spec name pfmt IFS=$'\n'
+  local -a aliases
+  aliases=()
+  for spec in $(git config --get-regexp '^pretty\.' 2>/dev/null); do
+    name="${${spec#pretty.}/ */}"
+    pfmt="${spec#pretty.$name }"
+    pfmt="$(sed 's_\([]:["]\)_\\\1_g' <<<"$pfmt")" # escapes ], :, [, and "
+    aliases+=(${name}'\:"git config alias for\: '${pfmt}'"')
+  done
+  pretty_aliases="${(pj:\n:)aliases}"
+}
+
+(( $+functions[__git_setup_pretty_options] )) ||
+__git_setup_pretty_options () {
+  local main fmts
+  main='oneline\:"commit-ids and subject of messages"
+        short\:"few headers and only subject of messages"
+        medium\:"most parts of messages"
+        full\:"all parts of commit messages"
+        fuller\:"like full and includes dates"
+        email\:"use email headers like From and Subject"
+        raw\:"the raw commits"
+        format\:"specify own format"
+        '
+  __git_setup_pretty_aliases
+  fmts='
+    %H\:"commit hash"
+    %h\:"abbreviated commit hash"
+    %T\:"tree hash"
+    %t\:"abbreviated tree hash"
+    %P\:"parent hashes"
+    %p\:"abbreviated parent hashes"
+    %an\:"author name"
+    %aN\:"author name (respecting .mailmap)"
+    %ae\:"author email"
+    %aE\:"author email (respecting .mailmap)"
+    %ad\:"author date (format respects --date= option)"
+    %aD\:"author date, RFC2822 style"
+    %ar\:"author date, relative"
+    %at\:"author date, UNIX timestamp"
+    %ai\:"author date, ISO 8601 format"
+    %cn\:"committer name"
+    %cN\:"committer name (respecting .mailmap)"
+    %ce\:"committer email"
+    %cE\:"committer email (respecting .mailmap)"
+    %cd\:"committer date"
+    %cD\:"committer date, RFC2822 style"
+    %cr\:"committer date, relative"
+    %ct\:"committer date, UNIX timestamp"
+    %ci\:"committer date, ISO 8601 format"
+    %d\:"ref names, like the --decorate option of git-log(1)"
+    %e\:"encoding"
+    %s\:"subject"
+    %f\:"sanitized subject line, suitable for a filename"
+    %b\:"body"
+    %B\:"raw body (unwrapped subject and body)"
+    %N\:"commit notes"
+    %gD\:"reflog selector, e.g., refs/stash@{1}"
+    %gd\:"shortened reflog selector, e.g., stash@{1}"
+    %gs\:"reflog subject"
+    %Cred\:"switch color to red"
+    %Cgreen\:"switch color to green"
+    %Cblue\:"switch color to blue"
+    %Creset\:"reset color"
+    %C(...)\:"color specification, as described in color.branch.* config option"
+    %m\:"left, right or boundary mark"
+    %n\:"newline"
+    %%\:"a raw %"
+    %x00\:"print a byte from a hex code"'
+  pretty_options='[pretty print commit messages]::format:(('${main}${pretty_aliases}${fmts}'))'
+}
+
+
 (( $+functions[__git_setup_revision_options] )) ||
 __git_setup_revision_options () {
   local -a diff_options
   __git_setup_diff_options
+  __git_setup_pretty_options
 
   revision_options=(
     $diff_options
     # TODO: format pretty print format is a lot more advanced than this.
     # TODO: You can’t actually specify --format without a format.
-    '(-v --header)'{--pretty=-,--format=-}'[pretty print commit messages]::format:((oneline\:"commit-ids and subject of messages"
-                                                                                    short\:"few headers and only subject of messages"
-                                                                                    medium\:"most parts of messages"
-                                                                                    full\:"all parts of commit messages"
-                                                                                    fuller\:"like full and includes dates"
-                                                                                    email\:"use email headers like From and Subject"
-                                                                                    raw\:"the raw commits"
-                                                                                    format\:"specify own format"))'
+    '(-v --header)'{--pretty=-,--format=-}${pretty_options}
     '--abbrev-commit[show only partial prefixes of commit object names]'
     '--oneline[shorthand for --pretty=oneline --abbrev-commit]'
     '--encoding=-[output log messages in given encoding]:: :__git_encodings'
-- 
1.7.4.1


[-- Attachment #3: _npm --]
[-- Type: application/octet-stream, Size: 529 bytes --]

#compdef npm

# Node Package Manager 0.3.15 completion, letting npm do all the completion work

_npm() {
  compadd -- $(_npm_complete $words)
}

# We want to show all errors of any substance, but never the "npm (not )ok" one.
# (Also doesn't consider "ERR! no match found" worth breaking the terminal for.)
_npm_complete() {
  local ask_npm
  ask_npm=(npm completion --color false --loglevel error -- $@)
  { _call_program npm $ask_npm 2>&1 >&3 \
  | egrep -v '^(npm (not |)ok|ERR! no match found)$' >&2; \
  } 3>&1
}

_npm "$@"

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-08-03 15:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-14  6:38 PATCH: git --pretty completion, and (new) completion for npm Johan Sundström
2011-03-20 10:35 ` Frank Terbeck
2011-03-20 11:52   ` Johan Sundström
2011-08-03 14:46     ` Nikolai Weibull
2011-08-03 15:05       ` Mikael Magnusson
2011-08-03 15:21         ` Nikolai Weibull

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).