#! /bin/sh for arg in $@; do option=`echo "'$arg'" | cut -d'=' -f1 | tr -d "'"` value=`echo "'$arg'" | cut -d'=' -f2- | tr -d "'"` if [ "$value" == "$option" ]; then value=""; fi case "$option" in -d|--git-dir) GIT_DIR=$value;; -t|--tasks-dir) TASKS_DIR=$value;; -c|--no-create) NO_CREATE=1;; -u|--force-update) FORCE_UPDATE=1;; *) GIT_REMOTE=$arg;; esac done GIT_DIR=${GIT_DIR:-$HOME/usr/git} TASKS_DIR=${TASKS_DIR:-$GIT_DIR/templates/ruby-gem/tasks} DIFF_OPTS=${DIFF_OPTS:--y --suppress-common-lines} NO_CREATE=${NO_CREATE:-0} FORCE_UPDATE=${ORCE_UPDATE:-0} RESET="\033[0m" RED="\033[0;31m" GREEN="\033[0;32m" BROWN="\033[0;33m" PURPLE="\033[0;35m" CYAN="\033[0;36m" YELLOW="\033[1;33m" function copy() { echo -e " copy ${PURPLE}${1}${RESET} into ${CYAN}${2}${RESET}" && cp ${1} ${2} } function update() { if [ $FORCE_UPDATE -eq 1 ]; then echo -n -e "\n${RED}${1}${RESET} : " && copy ${2} ${3} else echo -e "\n${RED}${1}${RESET} : ${PURPLE}${2} ${CYAN}${3}${RESET} differs ..." diff ${DIFF_OPTS} ${3} ${2} read -p " update it? [yN]" RET if [ "${RET}" = "Y" -o "${RET}" = "y" ]; then copy ${2} ${3} fi fi } function create() { echo -e "\n${RED}${1}${RESET} : ${CYAN}${3}${RESET} does not exists" read -p " create it? [yN]" RET if [ "${RET}" = "Y" -o "${RET}" = "y" ]; then copy ${2} ${3} fi } echo -e "task dir:${YELLOW}${TASKS_DIR}${RESET}" for gitdir in ${GIT_DIR}; do echo -e "enter ${BROWN}${gitdir}${RESET}" && cd ${gitdir} || return 1 for dir in $(ls -1); do [ -d ${dir} ] && [ -e ${dir}/tasks/gem.rake ] || continue # SEARCH REMOTE echo -e " enter ${BROWN}${dir}${RESET}" && cd $dir || exit 1 for task_file in ${TASKS_DIR}/*; do dest="./tasks/${task_file##*/}" if [ -e $dest ]; then cmp -s ${task_file} ${dest} || update ${dir} ${task_file} ${dest} elif [ $NO_CREATE -eq 0 ];then create ${dir} ${task_file} ${dest} fi done echo -e " leave ${BROWN}${dir}${RESET}\n" && cd .. || exit 1 done echo -e "leave ${BROWN}${gitdir}${RESET}" done