]> git.donarmstrong.com Git - zsh.git/blob - .zsh/func/giturl
more flexible giturl handling
[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
6 #
7 # Copyright © 2010 martin f. krafft <madduck@madduck.net>
8 # Released under the terms of the Artistic Licence 2.0
9 #
10 # Source repository: git://git.madduck.net/etc/zsh.git
11 #
12
13 local remote; remote=$(git config --get remote.origin.url)
14
15 local part gitweb_base oldstyle
16 oldstyle=0
17 case "$remote" in
18   madduck:pub/*)
19     gitweb_base=http://git.madduck.net/v
20     part="${remote#madduck:pub/}"
21     ;;
22   debian:*|*://git.debian.org/git/*|*@git.debian.org/git/*)
23     gitweb_base=http://git.debian.org
24     part="${remote#debian:}"
25     part="${part#*://git.debian.org/git/}"
26     part="${part#*@git.debian.org/git/}"
27     oldstyle=1
28     ;;
29   *)
30     echo >&2 "E: I do not know how to translate $REMOTE into a gitweb URL."
31     return 1
32     ;;
33 esac
34
35 local hash
36 hash=$(git rev-parse HEAD)
37
38 case "$oldstyle" in
39   0) echo "$gitweb_base/$part/commitdiff/$hash";;
40   *) echo "$gitweb_base/?p=$part;a=commitdiff;h=$hash";;
41 esac