git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: git list <git@vger.kernel.org>
Subject: simple git repository browser with vim
Date: Thu, 24 Nov 2005 01:33:22 -0800	[thread overview]
Message-ID: <20051124093322.GA3899@mail.yhbt.net> (raw)

Here's a really quick and easy way to browse git repositories for vim
users.  Hopefully somebody else finds this useful, I know I do.

The idea is just to open a temporary file with git sha1sums (say git-log
output) in vim, move your cursor over any one of the object sha1sums,
and then hit ,G (or any shortcut of your choice) in normal mode to
show what one of those was.

It relies on a simple shell script I wrote called 'git-show' that picks
a reasonable way to display each of the blob, tree, or commit object
types.  I'm fairly sure somebody else has written something like
git-show before, I just couldn't find it.  I'd imagine it's pretty
useful standalone without vim, too.

If you :set foldmethod=marker in vim, you can pass the -f
flag to git-show and it'll enclose the output with the the default
vim fold markers: {{{  }}}

This is the line I've added to my .vimrc:

	map ,G yaw:.!git-show -f <c-r>" <CR>

And here is git-show in all it's glory:
---

#!/bin/sh

while : ; do
	case "$1" in
	-f|--fold-marker)
		fold_marker=1
		;;
	*)
		if [ -z "$sha1sum" ]; then
			sha1sum="$1"
		fi
		break
		;;
	esac
	shift
done

type=`git-cat-file -t $sha1sum`

if [ -n "$fold_marker" ]; then
	echo "$type($1) {{{"
fi

case "$type" in
	tree)
		git-ls-tree -r $1
		;;
	blob)
		git-cat-file blob $1
		;;
	commit)
		git-cat-file commit $1
		echo ''
		git-whatchanged --max-count=1 -C -p -r $1
		;;
esac

if [ -n "$fold_marker" ]; then
	echo '}}}'
fi

-- 
Eric Wong

             reply	other threads:[~2005-11-24  9:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-24  9:33 Eric Wong [this message]
2005-11-24 10:28 ` simple git repository browser with vim Junio C Hamano
2005-11-26 22:05   ` Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051124093322.GA3899@mail.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).