]> git.madduck.net Git - etc/zsh.git/blob - .zsh/func/giturl

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

8f6233cb6308b76c655cf0a2e0d34c7eb12e37b1
[etc/zsh.git] / .zsh / func / giturl
1 #!/bin/sh
2 #
3 # func/giturl
4 #
5 # A convenient way to display the gitweb URL of a commit-ish, as well as the
6 # base URL and tree. Also for each argument, the tree or blob URL is printed.
7 #
8 # Copyright © 2010 martin f. krafft <madduck@madduck.net>
9 # Released under the terms of the Artistic Licence 2.0
10 #
11 # Source repository: git://git.madduck.net/etc/zsh.git
12 #
13
14 local remote; remote=$(git config --get remote.origin.url)
15
16 local part gitweb_base oldstyle
17 oldstyle=0
18 case "$remote" in
19   madduck:pub/*|ssh://git.madduck.net/madduck/pub/*)
20     gitweb_base=http://git.madduck.net/v
21     part="${remote#madduck:pub/}"
22     part="${part#ssh://git.madduck.net/madduck/pub/}"
23     part="${part%.git}.git"
24     ;;
25   debian:*|*://git.debian.org/git/*|*@git.debian.org/git/*)
26     gitweb_base=http://git.debian.org
27     part="${remote#debian:}"
28     part="${part#*://git.debian.org/git/}"
29     part="${part#*@git.debian.org/git/}"
30     part="${part%.git}.git"
31     oldstyle=1
32     ;;
33   *)
34     echo >&2 "E: I do not know how to translate $REMOTE into a gitweb URL."
35     return 1
36     ;;
37 esac
38
39 local hash
40 hash=$(git rev-parse HEAD)
41
42 case "$oldstyle" in
43   0)
44     echo "$gitweb_base/$part/commitdiff/$hash"
45     echo "$gitweb_base/$part/tree/HEAD"
46     for i in $@; do
47       [ -f "$i" ] && echo "$gitweb_base/$part/blob/HEAD:/$i"
48       [ -d "$i" ] && echo "$gitweb_base/$part/tree/HEAD:/$i"
49     done
50     ;;
51   *)
52     echo "$gitweb_base/?p=$part;a=commitdiff;h=$hash"
53     echo "$gitweb_base/?p=$part;a=tree;h=HEAD"
54     for i in $@; do
55       [ -f "$i" ] && echo "$gitweb_base/?p=$part;a=blob;hb=HEAD;f=$i"
56       [ -d "$i" ] && echo "$gitweb_base/?p=$part;a=tree;hb=HEAD;f=$i"
57     done
58     ;;
59 esac