diff --git a/zsh/plugins/project.plugin.zsh b/zsh/plugins/project.plugin.zsh new file mode 100644 index 0000000..deed78e --- /dev/null +++ b/zsh/plugins/project.plugin.zsh @@ -0,0 +1,62 @@ +_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') +} + +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 \ No newline at end of file