72 lines
1.3 KiB
Bash
72 lines
1.3 KiB
Bash
_PROJECT_DIR=$HOME/www/repo/
|
|
|
|
_project() {
|
|
compadd $(find $_PROJECT_DIR -maxdepth 1 -type d | sed 's#^\(.*\)/\([a-zA-Z0-9\._ -]*\)$#\2#g')
|
|
compadd $(find $_PROJECT_DIR -maxdepth 1 -type l | sed 's#^\(.*\)/\([a-zA-Z0-9\._ -]*\)$#\2#g')
|
|
}
|
|
|
|
gcll () {
|
|
REPO="$1"
|
|
DEST="$2"
|
|
if [ -z "$DEST" ]
|
|
then
|
|
DEST="$(basename "$REPO" | sed 's/\.git$//')"
|
|
fi
|
|
git clone "$REPO" && cd "$DEST"
|
|
}
|
|
|
|
repo() {
|
|
if [ "$1" = "-n" -a -n "$2" ]; then
|
|
TO="$3"
|
|
|
|
cd "$_PROJECT_DIR"
|
|
|
|
if [ -z "$3" ]; then
|
|
gcll "$2"
|
|
else
|
|
git clone "$2" "$3"
|
|
cd "$3"
|
|
fi
|
|
else
|
|
DIR="$_PROJECT_DIR/$1"
|
|
|
|
if [ -d "$DIR" ]; then
|
|
cd "$DIR"
|
|
else
|
|
echo "$1 is not an existing repository."
|
|
echo -n "Do you want to create a project? [O/n] "
|
|
read anwser
|
|
|
|
if [ "$anwser" = "" -o "$anwser" = "O" -o "$anwser" = "o" -o "$anwser" = "y" -o "$anwser" = "Y" ]; then
|
|
echo -n "URL of the repository: "
|
|
read anwser
|
|
|
|
if [ -n "$anwser" ]; then
|
|
repo -n "$anwser" "$1"
|
|
else
|
|
echo -n "Name of the repository [$1]: "
|
|
read anwser
|
|
|
|
if [ -z "$anwser" ]; then
|
|
anwser="$1"
|
|
fi
|
|
|
|
if [ ! -d "$anwser" ]; then
|
|
cd "$_PROJECT_DIR"
|
|
mkdir "$anwser"
|
|
cd "$anwser"
|
|
git init
|
|
else
|
|
repo "$anwser"
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ "$2" = "-g" ]; then
|
|
gvim ./
|
|
fi
|
|
fi
|
|
}
|
|
|
|
compdef _project repo |