]> 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:

let p return raw paste url
[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"
45     echo "$gitweb_base/$part/commitdiff/$hash"
46     echo "$gitweb_base/$part/tree/HEAD"
47     for i in $@; do
48       [ -f "$i" ] && echo "$gitweb_base/$part/blob/HEAD:/$i"
49       [ -d "$i" ] && echo "$gitweb_base/$part/tree/HEAD:/$i"
50     done
51     ;;
52   *)
53     echo "$gitweb_base/?p=$part"
54     echo "$gitweb_base/?p=$part;a=commitdiff;h=$hash"
55     echo "$gitweb_base/?p=$part;a=tree;h=HEAD"
56     for i in $@; do
57       [ -f "$i" ] && echo "$gitweb_base/?p=$part;a=blob;hb=HEAD;f=$i"
58       [ -d "$i" ] && echo "$gitweb_base/?p=$part;a=tree;hb=HEAD;f=$i"
59     done
60     ;;
61 esac