让你成为最历害的git提交人

5年以前  |  阅读数:2503 次  |  编程语言:Shell 

这个shell脚本,来源于https://github.com/KimDarren/git-faker。其逻辑很简单,就是通过不停的重复以下操作,使你成为最活跃的git用户:

  • 创建.git-faker目录
  • 生成文件
  • 提交文件
  • 删除之前提交的内容
#!/usr/bin/env sh

VERSION="0.2.0"

version() {
    printf "git-faker version %s\n" "$VERSION"
}

# Helpers.

current_year() {
    date +"%Y"
}

last_year() {
    year=$(current_year)
    echo $(( ${year#0} -1 ))
}

current_branch() {
    basename "$(git symbolic-ref HEAD)"
}

faker() {

    rm -rf .git-faker
    mkdir .git-faker

    if [ -z "$1" ]; then
        branch="$(current_branch)"
    else
        branch="$1"
    fi

    case "$2" in
        objc)
                extension="m"
                code="#import <UIKit/UIKit.h> @interface NSFaker () @end @implementation NSFaker - (instancetype)init { self = [super init]; if (self) {self.title = "faker";} return self; } @end " ;;
        js)
                extension="js"
                code="var express     = require('express'); console.log(express);" ;;
        java)
                extension="java"
                code="public class IntListVer1 {private static final int DEFAULT_CAP = 10;private int[] iValues;private int iSize;public IntListVer1(){this(DEFAULT_CAP);}}" ;;
        c)
                extension="c"
                code="#include <stdio.h> int main(){int c = 0;char ch, s[1000];gets(s);while (s[c] != '\0') {ch = s[c];if (ch >= 'A' && ch <= 'Z'){s[c] = s[c] + 32;}}return 0;}" ;;
        *)
                extension=""
                code="default" ;;
    esac

    git checkout $branch >/dev/null

    months=( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec )

    for month in ${months[@]}; do
        for day in {1..31}; do
            ranH=$RANDOM
            ranS=$RANDOM
            ranM=$RANDOM

            hour=$(( ranH %= 23 ))
            min=$(( ranM %= 59 ))
            sec=$(( ranS %= 59 ))

            echo "$code" > ".git-faker/$(current_year).$month.$day.$extension"
            git add -A >/dev/null
            GIT_AUTHOR_DATE="$month $day $hour:$min:$sec $(current_year) -0000" GIT_COMMITTER_DATE="$month $day $hour:$min:$sec $(current_year) -0000" git commit -m "I'm working hard.." >/dev/null

            echo "$code" > ".git-faker/$(last_year).$month.$day.$extension"
            git add -A >/dev/null
            GIT_AUTHOR_DATE="$month $day $hour:$sec:$min $(last_year) -0000" GIT_COMMITTER_DATE="$month $day $hour:$sec:$min $(last_year) -0000" git commit -m "I'm hustlin" >/dev/null
        done
    done

    printf "Great!\nYou should push to the GitHub!\nNow, you are the best commiter in the planet.\n"
}

display_help() {
    cat <<-EOF
  usage:
    git faker                       Execute git faker at current branch
  commands:
    git faker <branch>              Execute git faker with <branch> for commit
  options:
    -V, --version                   Output current version of git-faker
    -h, --help                      Display this help information
    --objc                          Set the language: Objective-C
    --java                          Set the language: Java
    --js                            Set the language: Javascript
    --c                             Set the language: C
EOF
    exit 0
}


case $1 in
    -V|--version) version; exit 0 ;;
    -h|--help) display_help; exit 0 ;;
    --objc) faker "$(current_branch)" "objc"; exit 0 ;;
    --java) faker "$(current_branch)" "java"; exit 0 ;;
    --js) faker "$(current_branch)" "js"; exit 0 ;;
    --c) faker "$(current_branch)" "c"; exit 0 ;;
esac

faker "$@"
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例