Skip to content

Instantly share code, notes, and snippets.

@nsleejian
Forked from cyrilis/README.md
Created January 17, 2017 05:35
Show Gist options
  • Select an option

  • Save nsleejian/489acea1e861e4325079ce1a23f96f67 to your computer and use it in GitHub Desktop.

Select an option

Save nsleejian/489acea1e861e4325079ce1a23f96f67 to your computer and use it in GitHub Desktop.

Revisions

  1. @cyrilis cyrilis revised this gist Jan 16, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Take a selfie every time you git commit

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

    通过 homebrew 安装 imagesnap:
  2. @cyrilis cyrilis created this gist Jan 16, 2017.
    47 changes: 47 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    本文仅写了 macOS 下的实践, 其他系统可参照修改。

    通过 homebrew 安装 imagesnap:

    ```shell
    brew install imagesnap
    ```

    在用户文件夹下新建 gitshot 文件夹:
    ```shell
    mkdir ~/gitshots
    ```

    创建 Git Template 文件夹:
    ```shell
    mkdir -p ~/.git-template/hooks
    ```
    创建 pre-commit git hook 文件: `~/.git-template/hooks/pre-commit`

    ```ruby
    #!/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 文件添加可执行权限:

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

    设置为 git 的初始化模板:
    ```shell
    git config --global init.templatedir '~/.git-template'
    ```
    Done!

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

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

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

    Happy Coding!