Skip to content

Instantly share code, notes, and snippets.

@cyrilis
Last active February 19, 2023 12:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cyrilis/f36812643bcbd79083c54a836938b2e6 to your computer and use it in GitHub Desktop.
Save cyrilis/f36812643bcbd79083c54a836938b2e6 to your computer and use it in GitHub Desktop.
Take a selfie every time you git commit

Take a selfie every time you git commit

本文仅写了 macOS 下的实践, 其他系统可参照修改。

通过 homebrew 安装 imagesnap:

brew install imagesnap

在用户文件夹下新建 gitshot 文件夹:

mkdir ~/gitshots

创建 Git Template 文件夹:

mkdir -p ~/.git-template/hooks

创建 pre-commit git hook 文件: ~/.git-template/hooks/pre-commit

#!/usr/bin/env ruby
file="~/gitshots/#{Time.now.to_i}.jpg"
unless File.directory?(File.expand_path("../../rebase-merge", __FILE__))
  puts "😃  -> #{file}!"
  system "imagesnap -q -w 1 #{file} &"
end
exit 0

给 pre-commit 文件添加可执行权限:

chmod +x ~/.git-template/hooks/pre-commit

设置为 git 的初始化模板:

git config --global init.templatedir '~/.git-template'

Done!

现在, 新创建和新克隆的 repo 里, 每次执行 git commit 都会用前置摄像头自拍一张,以时间戳为文件名,放入 ~/gitshots 文件夹下。

已经存在的 Repo,需要再次执行下 git init 即可。

大家还可以修改 pre-commit 文件,增加更多好玩脚本,比如添加上 git 的所在仓库名称,和 commit message 之类。

Happy Coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment