2011-10-21 19:28:04 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
cat <<\EOF
|
|
|
|
usage: git jump <mode> [<args>]
|
|
|
|
|
|
|
|
Jump to interesting elements in an editor.
|
|
|
|
The <mode> parameter is one of:
|
|
|
|
|
|
|
|
diff: elements are diff hunks. Arguments are given to diff.
|
|
|
|
|
|
|
|
merge: elements are merge conflicts. Arguments are ignored.
|
|
|
|
|
|
|
|
grep: elements are grep hits. Arguments are given to grep.
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
open_editor() {
|
|
|
|
editor=`git var GIT_EDITOR`
|
|
|
|
eval "$editor -q \$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
mode_diff() {
|
2012-09-17 03:21:55 +02:00
|
|
|
git diff --no-prefix --relative "$@" |
|
2011-10-21 19:28:04 +02:00
|
|
|
perl -ne '
|
2012-09-17 03:21:55 +02:00
|
|
|
if (m{^\+\+\+ (.*)}) { $file = $1; next }
|
2011-10-21 19:28:04 +02:00
|
|
|
defined($file) or next;
|
|
|
|
if (m/^@@ .*\+(\d+)/) { $line = $1; next }
|
|
|
|
defined($line) or next;
|
|
|
|
if (/^ /) { $line++; next }
|
|
|
|
if (/^[-+]\s*(.*)/) {
|
|
|
|
print "$file:$line: $1\n";
|
|
|
|
$line = undef;
|
|
|
|
}
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
mode_merge() {
|
|
|
|
git ls-files -u |
|
|
|
|
perl -pe 's/^.*?\t//' |
|
|
|
|
sort -u |
|
|
|
|
while IFS= read fn; do
|
|
|
|
grep -Hn '^<<<<<<<' "$fn"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Grep -n generates nice quickfix-looking lines by itself,
|
|
|
|
# but let's clean up extra whitespace, so they look better if the
|
|
|
|
# editor shows them to us in the status bar.
|
|
|
|
mode_grep() {
|
|
|
|
git grep -n "$@" |
|
|
|
|
perl -pe '
|
|
|
|
s/[ \t]+/ /g;
|
|
|
|
s/^ *//;
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
if test $# -lt 1; then
|
|
|
|
usage >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
mode=$1; shift
|
|
|
|
|
|
|
|
trap 'rm -f "$tmp"' 0 1 2 3 15
|
|
|
|
tmp=`mktemp -t git-jump.XXXXXX` || exit 1
|
|
|
|
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
|
|
|
|
"mode_$mode" "$@" >"$tmp"
|
|
|
|
test -s "$tmp" || exit 0
|
|
|
|
open_editor "$tmp"
|