-
-
Save cihat/7df7862c4d116f2b85e095470a45ecd4 to your computer and use it in GitHub Desktop.
gitlog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() { | |
echo "Usage: $0 -u=<github-username> [-f=<github-folder> -d=<number-of-days>]" | |
exit 1 | |
} | |
default_days=14 | |
default_github_folder=$HOME/Documents/GitHub/ | |
organization=jotform | |
while [[ "$#" -gt 0 ]]; do | |
case $1 in | |
-u=*) username="${1#*=}"; shift ;; | |
-f=*) github_folder="${1#*=}"; shift ;; | |
-d=*) number_of_days="${1#*=}"; shift ;; | |
*) usage ;; | |
esac | |
done | |
if [ -z "$username" ]; then | |
usage | |
fi | |
number_of_days="${number_of_days:-$default_days}" | |
github_folder="${github_folder:-$default_github_folder}" | |
github_folder=$(realpath "$github_folder") | |
since_date=$(date -v-"$number_of_days"d +%Y-%m-%d) | |
today=$(date +%Y-%m-%d) | |
output_file=~/commits_report.html | |
echo "<!DOCTYPE html> | |
<html lang=\"en\"> | |
<head> | |
<meta charset=\"UTF-8\"> | |
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> | |
<title>Commit Report</title> | |
<style> | |
a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:'';content:none}table{border-collapse:collapse;border-spacing:0} | |
@import url(https://fonts.cdnfonts.com/css/jetbrains-mono-2);body,hr{position:relative}hr,hr:after{display:block}body,hr:after,html{width:100%}h1,h2,h3,h4,h5,h6,strong{font-weight:var(--font-weight-bold)}body,h1,h2,h3,h4,h5,h6,td,th{line-height:var(--line-height)}.header h1,.tree ul,body,figure pre,html,sub{margin:0}:root,code,pre{font-family:var(--font-family)}figure,pre{overflow-x:auto}em,figcaption{font-style:italic}*+*,figcaption{margin-top:var(--line-height)}button,details,input,td,textarea,th{border:var(--border-thickness) solid var(--text-color)}button,html,input,textarea{background:var(--background-color);color:var(--text-color)}a:link,a:visited,button,hr,html,input,textarea{color:var(--text-color)}hr,input[type=checkbox]{height:var(--line-height)}html,li,ol{padding:0}button,h1,h2{text-transform:uppercase}.tree ul li:before,table{top:calc(var(--line-height)/ 2)}.tree ul li,.tree ul li:last-child:after{border-left:var(--border-thickness) solid var(--text-color)}.grid,html{display:flex}.debug .debug-grid,.tree ul li:before,hr:after{position:absolute;left:0}:root{--font-family:"JetBrains Mono",monospace;--line-height:1.20rem;--border-thickness:2px;--text-color:#000;--text-color-alt:#666;--background-color:#fff;--background-color-alt:#eee;--font-weight-normal:500;--font-weight-medium:600;--font-weight-bold:800;font-optical-sizing:auto;font-weight:var(--font-weight-normal);font-style:normal;font-variant-numeric:tabular-nums lining-nums;font-size:16px}@media (prefers-color-scheme:dark){:root{--text-color:#fff;--text-color-alt:#aaa;--background-color:#000;--background-color-alt:#111}}*{box-sizing:border-box}html{flex-direction:column;align-items:center}body{padding:var(--line-height) 2ch;max-width:calc(min(120ch,round(down,100%,1ch)))}@media screen and (max-width:480px){:root{font-size:14px}body{padding:var(--line-height) 1ch}}h1,h2,h3,h4,h5,h6{margin:calc(var(--line-height) * 2) 0 var(--line-height)}.header,h1{margin-bottom:calc(var(--line-height) * 2)}h1{font-size:2rem;line-height:calc(2 * var(--line-height))}h2{font-size:1rem}hr{margin:calc(var(--line-height) * 1.5) 0;border:none}hr:after{content:"";top:calc(var(--line-height)/ 2 - var(--border-thickness));border-top:calc(var(--border-thickness) * 3) double var(--text-color);height:0}.tree,.tree ul,.tree ul li,sub,table{position:relative}a{text-decoration-thickness:var(--border-thickness)}p{margin-bottom:var(--line-height);word-break:break-word;word-wrap:break-word;hyphens:auto}sub{display:inline-block;vertical-align:sub;line-height:0;width:calc(1ch / .75);font-size:.75rem}table{width:calc(round(down,100%,1ch));border-collapse:collapse;margin:0 0 calc(var(--line-height) * 2)}td,th{padding:calc((var(--line-height)/ 2)) calc(1ch - var(--border-thickness)/ 2) calc((var(--line-height)/ 2) - (var(--border-thickness)));vertical-align:top;text-align:left}table tbody tr:first-child>*{padding-top:calc((var(--line-height)/ 2) - var(--border-thickness))}th{font-weight:700}code,ol li:before,summary{font-weight:var(--font-weight-medium)}.width-min{width:0%}.width-auto,img,label input,video{width:100%}.grid,details,details[open] summary{margin-bottom:var(--line-height)}.debug-toggle-label,.header tr td:last-child{text-align:right}img,video{display:block;object-fit:contain}details{padding:calc(var(--line-height) - var(--border-thickness)) 1ch}details ::marker{display:inline-block;content:'▶';margin:0}details[open] ::marker{content:'▼'}details :last-child{margin-bottom:0}pre{white-space:pre;margin:var(--line-height) 0}figure{margin:calc(var(--line-height) * 2) 3ch}figcaption{display:block}ol,ul{margin:0 0 var(--line-height)}ul{list-style-type:square;padding:0 0 0 2ch}.tree,.tree ul,ol{list-style-type:none}ol{counter-reset:item}ol ol,ol ul,ul ol,ul ul{padding:0 0 0 3ch;margin:0}ol li:before{content:counters(item, ".") ". ";counter-increment:item}li{margin:0}li::marker{line-height:0}::-webkit-scrollbar{height:var(--line-height)}button,input,textarea{padding:calc(var(--line-height)/ 2 - var(--border-thickness)) calc(1ch - var(--border-thickness));margin:0;font:inherit;font-weight:inherit;height:calc(var(--line-height) * 2);width:auto;overflow:visible;line-height:normal;-webkit-font-smoothing:inherit;-moz-osx-font-smoothing:inherit;-webkit-appearance:none}button,label{font-weight:var(--font-weight-medium)}input,label{width:calc(round(down,100%,1ch))}.tree,.tree ul,label{line-height:var(--line-height)}input[type=checkbox]{display:inline-grid;place-content:center;vertical-align:top;width:2ch;cursor:pointer}input[type=checkbox]:checked:before{content:"";width:1ch;height:calc(var(--line-height)/ 2);background:var(--text-color)}button:focus,input:focus{--border-thickness:3px;outline:0}::placeholder{color:var(--text-color-alt);opacity:1}::-ms-input-placeholder{color:var(--text-color-alt)}button::-moz-focus-inner{padding:0;border:0}button{cursor:pointer}button:hover{background:var(--background-color-alt)}button:active{transform:translate(2px,2px)}label{display:block;height:auto;margin:0}.tree,.tree ul{padding-left:0}.tree ul li{padding-left:1.5ch;margin-left:1.5ch}.tree ul li:before{display:block;content:"";width:1ch;border-bottom:var(--border-thickness) solid var(--text-color)}.tree ul li:last-child{border-left:none}.tree ul li:last-child:after{position:absolute;display:block;top:0;left:0;content:"";height:calc(var(--line-height)/ 2)}.grid{--grid-cells:0;gap:1ch;width:calc(round(down,100%,(1ch * var(--grid-cells)) - (1ch * var(--grid-cells) - 1)))}.grid>*,.grid>input{flex:0 0 calc(round(down,(100% - (1ch * (var(--grid-cells) - 1)))/ var(--grid-cells),1ch))}.grid:has(> :last-child:first-child){--grid-cells:1}.grid:has(> :last-child:nth-child(2)){--grid-cells:2}.grid:has(> :last-child:nth-child(3)){--grid-cells:3}.grid:has(> :last-child:nth-child(4)){--grid-cells:4}.grid:has(> :last-child:nth-child(5)){--grid-cells:5}.grid:has(> :last-child:nth-child(6)){--grid-cells:6}.grid:has(> :last-child:nth-child(7)){--grid-cells:7}.grid:has(> :last-child:nth-child(8)){--grid-cells:8}.grid:has(> :last-child:nth-child(9)){--grid-cells:9}.debug .debug-grid{--color:color-mix(in srgb, var(--text-color) 10%, var(--background-color) 90%);top:0;right:0;bottom:0;z-index:-1;background-image:repeating-linear-gradient(var(--color) 0 1px,transparent 1px 100%),repeating-linear-gradient(90deg,var(--color) 0 1px,transparent 1px 100%);background-size:1ch var(--line-height);margin:0}.debug .off-grid{background:rgba(255,0,0,.1)} | |
</style> | |
</head> | |
<body> | |
<table class="header"> | |
<tr> | |
<td colspan="2" rowspan="2" class="width-auto"> | |
<h1 class="title">Commit Report</h1> | |
<span class="subtitle">in local git repos for the last ${number_of_days} days</span> | |
</td> | |
<th>User</th> <td class="width-min">${username}</td> | |
</tr> | |
<tr> | |
<th>Date</th> <td class="width-min">${today}</td> | |
</tr> | |
<tr> | |
<th class="width-min">Folder</th> <td class="width-auto">${github_folder}</td> | |
<th class="width-min">Since</th> <td>${since_date}</td> | |
</tr> | |
</table> | |
" > "$output_file" | |
for repo in "$github_folder"/*; do | |
if [ -d "$repo/.git" ]; then # Check if it's a Git repository | |
repo_name=$(basename "$repo") # Extract the repository name | |
echo $repo_name | |
cd "$repo" || exit | |
temp_file=$(mktemp) | |
git log master --since="$since_date" --all --grep="$username" --pretty=format:"<div class=\"commit\"><p><a target=\"_blank\" href=\"https://github.com/$organization/$repo_name/commit/%H\">%h</a> | %ad | %s</p></div>" --date=short >> "$temp_file" | |
git log master --since="$since_date" --author="$username" --pretty=format:"<div class=\"commit\"><p><a target=\"_blank\" href=\"https://github.com/$organization/$repo_name/commit/%H\">%h</a> | %ad | %s</p></div>" --date=short >> "$temp_file" | |
if [ -s "$temp_file" ]; then | |
echo "<details open> | |
<summary>$repo_name</summary>" >> "$output_file" | |
cat "$temp_file" >> "$output_file" | |
echo "</details>" >> "$output_file" | |
fi | |
else | |
echo "Skipping $repo - not a git repository" | |
fi | |
done | |
echo "</body> | |
</html>" >> "$output_file" | |
if command -v xdg-open &> /dev/null; then | |
xdg-open "$output_file" # For Linux | |
elif command -v open &> /dev/null; then | |
open "$output_file" # For macOS | |
else | |
echo "No command to open the HTML file found. Please open $output_file manually." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment