git-jump: add an optional argument '--stdout'
It can be used with M-x grep on Emacs. Signed-off-by: Yoichi Nakayama <yoichi.nakayama@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Yoichi Nakayama committed
Nov 27, 2022 at 01:18 UTC
cfb7b3b39183e9711340ee464e58199f44e0de4e
2 files changed
+33
-2
contrib/git-jump/README
+9
-1
@@ -79,6 +79,14 @@ git jump grep -i foo_bar
79
git config jump.grepCmd "ag --column"
80
--------------------------------------------------
81
82
+You can use the optional argument '--stdout' to print the listing to
83
+standard output instead of feeding it to the editor. You can use the
84
+argument with M-x grep on Emacs:
85
+
86
+--------------------------------------------------
87
+# In Emacs, M-x grep and invoke "git jump --stdout <mode>"
88
+M-x grep<RET>git jump --stdout diff<RET>
89
+--------------------------------------------------
90
91
Related Programs
92
----------------
@@ -100,7 +108,7 @@ Limitations
108
-----------
109
110
This script was written and tested with vim. Given that the quickfix
103
-format is the same as what gcc produces, I expect emacs users have a
111
+format is the same as what gcc produces, I expect other tools have a
112
similar feature for iterating through the list, but I know nothing about
113
how to activate it.
114
contrib/git-jump/git-jump
+24
-1
@@ -2,7 +2,7 @@
2
3
usage() {
4
cat <<\EOF
5
-usage: git jump <mode> [<args>]
5
+usage: git jump [--stdout] <mode> [<args>]
6
7
Jump to interesting elements in an editor.
8
The <mode> parameter is one of:
@@ -15,6 +15,9 @@ grep: elements are grep hits. Arguments are given to git grep or, if
15
configured, to the command in `jump.grepCmd`.
16
17
ws: elements are whitespace errors. Arguments are given to diff --check.
18
+
19
+If the optional argument `--stdout` is given, print the quickfix
20
+lines to standard output instead of feeding it to the editor.
21
EOF
22
}
23
@@ -64,11 +67,31 @@ mode_ws() {
67
git diff --check "$@"
68
}
69
70
+use_stdout=
71
+while test $# -gt 0; do
72
+ case "$1" in
73
+ --stdout)
74
+ use_stdout=t
75
+ ;;
76
+ --*)
77
+ usage >&2
78
+ exit 1
79
+ ;;
80
+ *)
81
+ break
82
+ ;;
83
+ esac
84
+ shift
85
+done
86
if test $# -lt 1; then
87
usage >&2
88
exit 1
89
fi
90
mode=$1; shift
91
+if test "$use_stdout" = "t"; then
92
+ "mode_$mode" "$@"
93
+ exit 0
94
+fi
95
96
trap 'rm -f "$tmp"' 0 1 2 3 15
97
tmp=`mktemp -t git-jump.XXXXXX` || exit 1