diff options
Diffstat (limited to 'contrib/git-jump/git-jump')
-rwxr-xr-x | contrib/git-jump/git-jump | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump index 931b0fe..47e0c55 100755 --- a/contrib/git-jump/git-jump +++ b/contrib/git-jump/git-jump @@ -2,25 +2,43 @@ usage() { cat <<\EOF -usage: git jump <mode> [<args>] +usage: git jump [--stdout] <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. +merge: elements are merge conflicts. Arguments are given to ls-files -u. grep: elements are grep hits. Arguments are given to git grep or, if configured, to the command in `jump.grepCmd`. ws: elements are whitespace errors. Arguments are given to diff --check. + +If the optional argument `--stdout` is given, print the quickfix +lines to standard output instead of feeding it to the editor. EOF } open_editor() { editor=`git var GIT_EDITOR` - eval "$editor -q \$1" + case "$editor" in + *emacs*) + # Supported editor values are: + # - emacs + # - emacsclient + # - emacsclient -t + # + # Wait for completion of the asynchronously executed process + # to avoid race conditions in case of "emacsclient". + eval "$editor --eval \"(let ((buf (grep \\\"cat \$1\\\"))) (pop-to-buffer buf) (select-frame-set-input-focus (selected-frame)) (while (get-buffer-process buf) (sleep-for 0.1)))\"" + ;; + *) + # assume anything else is vi-compatible + eval "$editor -q \$1" + ;; + esac } mode_diff() { @@ -39,7 +57,7 @@ mode_diff() { } mode_merge() { - git ls-files -u | + git ls-files -u "$@" | perl -pe 's/^.*?\t//' | sort -u | while IFS= read fn; do @@ -64,15 +82,36 @@ mode_ws() { git diff --check "$@" } +use_stdout= +while test $# -gt 0; do + case "$1" in + --stdout) + use_stdout=t + ;; + --*) + usage >&2 + exit 1 + ;; + *) + break + ;; + esac + shift +done if test $# -lt 1; then usage >&2 exit 1 fi mode=$1; shift +type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; } + +if test "$use_stdout" = "t"; then + "mode_$mode" "$@" + exit 0 +fi 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" |