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

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:

abbreviations should be two chars!
[etc/zsh.git] / .zsh / func / vcsh
1 #!/bin/zsh
2 #
3 # func/vcsh
4 #
5 # set the context for vcs-home operations
6 #
7 # Copyright © 1994–2008 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 FGIT_BASE="$HOME/.fgits"
14
15 if [[ "$1" == '-l' ]]
16 then
17    for i in $FGIT_BASE/*.git
18    do
19       i="${i#$FGIT_BASE/}"
20       echo "${i%.git}"
21    done
22    return 0
23 elif [[ "$1" == '-c' ]]
24 then
25    shift
26
27    if [[ -z "$1" ]]
28    then
29       echo "E: no repository name given" >&2
30       return 2
31    fi
32    if [[ -e "$FGIT_BASE/${1}.git" ]]
33    then
34       echo "E: repository '$1' still exists" >&2
35       return 2
36    fi
37
38    git init --bare "$FGIT_BASE/${1}.git"
39    cd "$FGIT_BASE/${1}.git"
40    git config core.bare false
41    git config core.worktree ../../
42    git config core.excludesfile "$FGIT_BASE/${1}.ignore"
43    cd -
44
45    [[ -e "$FGIT_BASE/${1}.ignore" ]] || echo "/*" > "$FGIT_BASE/${1}.ignore"
46 fi
47 if [[ "${1:---help}" == '--help' ]] || [[ $# -gt 1 ]]
48 then
49    echo "usage: ${0##*/} reponame" >&2
50    echo "usage: ${0##*/} -l" >&2
51    echo "usage: ${0##*/} -c reponame" >&2
52    [ "$1" = '--help' ]
53    return $?
54 fi
55
56 if [ ! -d "$FGIT_BASE/${1}.git" ]; then
57   echo E: no repository found for "$1" >&2
58   return 2
59 fi
60
61 old_GIT_DIR="${GIT_DIR:-}"
62 old_GIT_WORK_TREE="${GIT_WORK_TREE:-}"
63
64 export GIT_DIR="$FGIT_BASE/${1}.git"
65 export GIT_WORK_TREE="$GIT_DIR/$(git config --get core.worktree)"
66
67 PS1="%S{${0##*/}:$1}%s$PS1" $SHELL -i || :
68
69 GIT_DIR="$old_GIT_DIR"
70 [ -z "$GIT_DIR" ] && unset GIT_DIR
71 GIT_WORK_TREE="$old_GIT_WORK_TREE"
72 [ -z "$GIT_WORK_TREE" ] && unset GIT_WORK_TREE