grep: Add the option '--open-files-in-pager'

This adds an option to open the matching files in the pager, and if the
pager happens to be "less" (or "vi") and there is only one grep pattern,
it also jumps to the first match right away.

The short option was chose as '-O' to avoid clashes with GNU grep's
options (as suggested by Junio).

So, 'git grep -O abc' is a short form for 'less +/abc $(grep -l abc)'
except that it works also with spaces in file names, and it does not
start the pager if there was no matching file.

[jn: rebased and added tests; with error handling fix from Junio
squashed in]

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 files changed
tree: 27f426c9db30f349d54e56cb28ee91c37ef2a050
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. git-gui/
  7. git_remote_helpers/
  8. gitk-git/
  9. gitweb/
  10. perl/
  11. ppc/
  12. t/
  13. templates/
  14. xdiff/
  15. .gitattributes
  16. .gitignore
  17. .mailmap
  18. abspath.c
  19. advice.c
  20. advice.h
  21. alias.c
  22. alloc.c
  23. archive-tar.c
  24. archive-zip.c
  25. archive.c
  26. archive.h
  27. attr.c
  28. attr.h
  29. base85.c
  30. bisect.c
  31. bisect.h
  32. blob.c
  33. blob.h
  34. branch.c
  35. branch.h
  36. builtin.h
  37. bundle.c
  38. bundle.h
  39. cache-tree.c
  40. cache-tree.h
  41. cache.h
  42. check-builtins.sh
  43. check-racy.c
  44. check_bindir
  45. color.c
  46. color.h
  47. combine-diff.c
  48. command-list.txt
  49. commit.c
  50. commit.h
  51. config.c
  52. config.mak.in
  53. configure.ac
  54. connect.c
  55. convert.c
  56. copy.c
  57. COPYING
  58. csum-file.c
  59. csum-file.h
  60. ctype.c
  61. daemon.c
  62. date.c
  63. decorate.c
  64. decorate.h
  65. delta.h
  66. diff-delta.c
  67. diff-lib.c
  68. diff-no-index.c
  69. diff.c
  70. diff.h
  71. diffcore-break.c
  72. diffcore-delta.c
  73. diffcore-order.c
  74. diffcore-pickaxe.c
  75. diffcore-rename.c
  76. diffcore.h
  77. dir.c
  78. dir.h
  79. editor.c
  80. entry.c
  81. environment.c
  82. exec_cmd.c
  83. exec_cmd.h
  84. fast-import.c
  85. fetch-pack.h
  86. fixup-builtins
  87. fsck.c
  88. fsck.h
  89. generate-cmdlist.sh
  90. git-add--interactive.perl
  91. git-am.sh
  92. git-archimport.perl
  93. git-bisect.sh
  94. git-compat-util.h
  95. git-cvsexportcommit.perl
  96. git-cvsimport.perl
  97. git-cvsserver.perl
  98. git-difftool--helper.sh
  99. git-difftool.perl
  100. git-filter-branch.sh
  101. git-instaweb.sh
  102. git-lost-found.sh
  103. git-merge-octopus.sh
  104. git-merge-one-file.sh
  105. git-merge-resolve.sh
  106. git-mergetool--lib.sh
  107. git-mergetool.sh
  108. git-parse-remote.sh
  109. git-pull.sh
  110. git-quiltimport.sh
  111. git-rebase--interactive.sh
  112. git-rebase.sh
  113. git-relink.perl
  114. git-remote-testgit.py
  115. git-repack.sh
  116. git-request-pull.sh
  117. git-send-email.perl
  118. git-sh-setup.sh
  119. git-stash.sh
  120. git-submodule.sh
  121. git-svn.perl
  122. GIT-VERSION-GEN
  123. git-web--browse.sh
  124. git.c
  125. git.spec.in
  126. graph.c
  127. graph.h
  128. grep.c
  129. grep.h
  130. hash.c
  131. hash.h
  132. help.c
  133. help.h
  134. hex.c
  135. http-backend.c
  136. http-fetch.c
  137. http-push.c
  138. http-walker.c
  139. http.c
  140. http.h
  141. ident.c
  142. imap-send.c
  143. INSTALL
  144. levenshtein.c
  145. levenshtein.h
  146. list-objects.c
  147. list-objects.h
  148. ll-merge.c
  149. ll-merge.h
  150. lockfile.c
  151. log-tree.c
  152. log-tree.h
  153. mailmap.c
  154. mailmap.h
  155. Makefile
  156. match-trees.c
  157. merge-file.c
  158. merge-recursive.c
  159. merge-recursive.h
  160. name-hash.c
  161. notes-cache.c
  162. notes-cache.h
  163. notes.c
  164. notes.h
  165. object.c
  166. object.h
  167. pack-check.c
  168. pack-refs.c
  169. pack-refs.h
  170. pack-revindex.c
  171. pack-revindex.h
  172. pack-write.c
  173. pack.h
  174. pager.c
  175. parse-options.c
  176. parse-options.h
  177. patch-delta.c
  178. patch-ids.c
  179. patch-ids.h
  180. path.c
  181. pkt-line.c
  182. pkt-line.h
  183. preload-index.c
  184. pretty.c
  185. progress.c
  186. progress.h
  187. quote.c
  188. quote.h
  189. reachable.c
  190. reachable.h
  191. read-cache.c
  192. README
  193. reflog-walk.c
  194. reflog-walk.h
  195. refs.c
  196. refs.h
  197. remote-curl.c
  198. remote.c
  199. remote.h
  200. replace_object.c
  201. rerere.c
  202. rerere.h
  203. resolve-undo.c
  204. resolve-undo.h
  205. revision.c
  206. revision.h
  207. run-command.c
  208. run-command.h
  209. send-pack.h
  210. server-info.c
  211. setup.c
  212. sha1-lookup.c
  213. sha1-lookup.h
  214. sha1_file.c
  215. sha1_name.c
  216. shallow.c
  217. shell.c
  218. shortlog.h
  219. show-index.c
  220. sideband.c
  221. sideband.h
  222. sigchain.c
  223. sigchain.h
  224. strbuf.c
  225. strbuf.h
  226. string-list.c
  227. string-list.h
  228. submodule.c
  229. submodule.h
  230. symlinks.c
  231. tag.c
  232. tag.h
  233. tar.h
  234. test-chmtime.c
  235. test-ctype.c
  236. test-date.c
  237. test-delta.c
  238. test-dump-cache-tree.c
  239. test-genrandom.c
  240. test-index-version.c
  241. test-match-trees.c
  242. test-parse-options.c
  243. test-path-utils.c
  244. test-run-command.c
  245. test-sha1.c
  246. test-sha1.sh
  247. test-sigchain.c
  248. thread-utils.c
  249. thread-utils.h
  250. trace.c
  251. transport-helper.c
  252. transport.c
  253. transport.h
  254. tree-diff.c
  255. tree-walk.c
  256. tree-walk.h
  257. tree.c
  258. tree.h
  259. unimplemented.sh
  260. unpack-trees.c
  261. unpack-trees.h
  262. upload-pack.c
  263. usage.c
  264. userdiff.c
  265. userdiff.h
  266. utf8.c
  267. utf8.h
  268. walker.c
  269. walker.h
  270. wrap-for-bin.sh
  271. wrapper.c
  272. write_or_die.c
  273. ws.c
  274. wt-status.c
  275. wt-status.h
  276. xdiff-interface.c
  277. xdiff-interface.h