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

move systemd aliases to systemd repo
[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 # Contributions from Yaroslav O. Halchenko <debian@onerussian.com>
11 #
12 # Source repository: http://git.madduck.net/v/etc/zsh.git
13 #
14
15 local branch remote remote_name
16 branch=$(git symbolic-ref -q HEAD); branch="${branch#refs/heads/}"
17 # Obtain remote which current branch tracks, origin if not known
18 remote_name=$(git config branch.$branch.remote || echo origin)
19 remote=$(git config --get remote.$remote_name.url)
20
21 local part gitweb_base style commitkw
22 style=gitweb
23 commitkw=commitdiff          # keyword for commit -- differ for github
24 argssep=:                    # separator for arguments of the query
25 case "$remote" in
26   madduck:pub/*|ssh://git.madduck.net/madduck/pub/*)
27     gitweb_base=http://git.madduck.net/v
28     part="${remote#madduck:pub/}"
29     part="${part#ssh://git.madduck.net/madduck/pub/}"
30     part="${part%.git}.git"
31     ;;
32   debian:*|*://git.debian.org/git/*|*://alioth.debian.org/git/*|*@git.debian.org/git/*)
33     gitweb_base=http://git.debian.org
34     part="${remote#debian:}"
35     part="${part#*://git.debian.org/git/}"
36     part="${part#*://alioth.debian.org/git/}"
37     part="${part#*@git.debian.org/git/}"
38     part="${part%.git}.git"
39     style=gitweb_old
40     ;;
41   github:*|*://github.com/*|*@github.com[/:]*)
42     gitweb_base=http://github.com
43     part="${remote#github:}"
44     part="${part#*://github.com/}"
45     part="${part#*@github.com[:/]}"
46     part="${part%.git}"
47     style=github
48     commitkw=commit
49     argssep=
50     ;;
51   *)
52     echo >&2 "E: I do not know how to translate $remote into a gitweb URL."
53     return 1
54     ;;
55 esac
56
57 local hash
58 hash=$(git rev-parse HEAD)
59
60 case "$style" in
61   gitweb|github)
62     echo "$gitweb_base/$part"
63     echo "$gitweb_base/$part/$commitkw/$hash"
64     echo "$gitweb_base/$part/tree/HEAD"
65     for i in $@; do
66       [ -f "$i" ] && echo "$gitweb_base/$part/blob/HEAD${argssep}/$i"
67       [ -d "$i" ] && echo "$gitweb_base/$part/tree/HEAD${argssep}/$i"
68     done
69     ;;
70   gitweb_old)
71     echo "$gitweb_base/?p=$part"
72     echo "$gitweb_base/?p=$part;a=commitdiff;h=$hash"
73     echo "$gitweb_base/?p=$part;a=tree;h=HEAD"
74     for i in $@; do
75       [ -f "$i" ] && echo "$gitweb_base/?p=$part;a=blob;hb=HEAD;f=$i"
76       [ -d "$i" ] && echo "$gitweb_base/?p=$part;a=tree;hb=HEAD;f=$i"
77     done
78     ;;
79 esac