编辑
2024-10-25
后端
00
请注意,本文编写于 197 天前,最后修改于 197 天前,其中某些信息可能已经过时。

Keep Your Contribution activity In Every Day.

sh
#!/bin/bash # 定义颜色代码 RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[0;33m' BLUE='\033[0;34m' PINK='\033[0;35m' NC='\033[0m' # No Color # 日志函数 log() { local level=$1 local message=$2 local color="" local prefix="[Min]" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') case $level in "Info") color=$GREEN ;; "Error") color=$RED ;; "Warn") color=$YELLOW ;; *) color=$NC ;; esac echo -e "${PINK}${prefix} ${BLUE}${timestamp} ${color}${message}${NC}" } log "Info" "Start GitHub Keep Tool." log "Info" "Keep Your Contribution activity In Every Day." # 检查参数是否为空 if [ $# -eq 0 ]; then log "Error" "times not found" exit 1 fi n=$1 # 检查参数是否为数字 if ! [[ "$n" =~ ^[0-9]+$ ]]; then log "Error" "times is not a number" exit 1 fi # 创建code目录(如果不存在) mkdir -p ./code for (( i=1; i<= n; i++ )); do timestamp=$(date +%s) log "Info" "Current time is $timestamp" log "Info" "Creating $timestamp.go" content=" package main import \"fmt\" // GetDayInfo returns the current date in YYMMDD format qwmqwmzyhzyh func GetDayInfo() string { return \"$timestamp\" } func main() { fmt.Println(GetDayInfo()) } " filename="./code/$timestamp.go" touch $filename log "Info" "Writing content to $filename..." echo "$content" > $filename git add $filename git commit -m "$timestamp commit" git push if [ $? -eq 0 ]; then log "Info" "Git push successful." else log "Error" "Git push failed." fi done log "Info" "GitHub Keep Tool completed."

image.png

本文作者:yowayimono

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!