Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions contrib/git-jump/README
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,20 @@ git jump grep foo_bar
# arbitrary grep options
git jump grep -i foo_bar

# jump to places with conflict markers or whitespace errors
# (as reported by `git diff --check`)
git jump ws

# use the silver searcher for git jump grep
git config jump.grepCmd "ag --column"

# pick a mode automatically: "merge" if there are unmerged paths,
# "diff" if the worktree has unstaged changes, "ws" if there are
# whitespace problems; otherwise show usage
git jump auto

# with no explicit mode and no args, same as "auto"
git jump
--------------------------------------------------

You can use the optional argument '--stdout' to print the listing to
Expand Down
26 changes: 23 additions & 3 deletions contrib/git-jump/git-jump
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
usage() {
cat <<\EOF
usage: git jump [--stdout] <mode> [<args>]
or: git jump [--stdout]

Jump to interesting elements in an editor.
The <mode> parameter is one of:
The <mode> parameter is one of the following.
With no <mode> and no <args>, it defaults to "auto".

diff: elements are diff hunks. Arguments are given to diff.

Expand All @@ -16,6 +18,10 @@ grep: elements are grep hits. Arguments are given to git grep or, if

ws: elements are whitespace errors. Arguments are given to diff --check.

auto: select one of the other modes based on worktree state;
"merge" if there are unmerged paths, "diff" if there are
unstaged changes, "ws" if there are whitespace errors.

If the optional argument `--stdout` is given, print the quickfix
lines to standard output instead of feeding it to the editor.
EOF
Expand Down Expand Up @@ -82,6 +88,21 @@ mode_ws() {
git diff --check "$@"
}

mode_auto() {
if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true"; then
usage >&2
exit 1
fi
if test -n "$(git ls-files -u "$@")"; then
mode_merge "$@"
elif ! git diff --quiet "$@"; then
mode_diff "$@"
else
usage >&2
exit 1
fi
}

use_stdout=
while test $# -gt 0; do
case "$1" in
Expand All @@ -99,8 +120,7 @@ while test $# -gt 0; do
shift
done
if test $# -lt 1; then
usage >&2
exit 1
set -- auto
fi
mode=$1; shift
type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }
Expand Down
Loading