PHP
·
发表于 5年以前
·
阅读量:8285
这个shell脚本,来源于https://github.com/KimDarren/git-faker。其逻辑很简单,就是通过不停的重复以下操作,使你成为最活跃的git用户:
#!/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 "$@"