Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ If you wrote one of these scripts and want it removed from this collection, plea
| `git-plotrepo` | Matthew McCullogh's [scripts collection](https://github.com/matthewmccullough/scripts/blob/master/git-plotrepo.rb) | Uses dot to draw a graph of the repository. |
| `git-pr-fetch` | Joe Block <jpb@unixorn.net> | Fetch PR branches by refspec from one of a repository's remotes. |
| `git-pr-list` | Joe Block <jpb@unixorn.net> | Lists pull requests. Requires `gh`. |
| `git-review-commits` | Julia Evans'[blog](https://jvns.ca/til/fzf-preview-git-commits/) | Use [fzf](https://github.com/junegunn/fzf) topreview commits |
| `git-promote` | Trevor's **Improving My git Workflow** blog post (404 now) | Promotes a local topic branch to a remote tracking branch of the same name. |
| `git-prune-branches` | Michael Demmer in [jut-io/git-scripts](https://github.com/jut-io/git-scripts/blob/master/bin/git-prune-branches) | Deletes each fully merged branch after prompting for confirmation, than asks if you want the deleted branches deleted from your upstream remotes. |
| `git-pruneall` | Ryan Tomayko's dotfiles | Prune branches from specified remotes, or all remotes when no remote is specified. |
Expand Down Expand Up @@ -309,6 +310,7 @@ If you aren't using any ZSH frameworks, or if you're using `bash`, `fish` or ano
- [commit-helper](https://github.com/andre-filho/commit-helper) - A python script that helps you write commits following commit conventions.
- [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy) - Better looking `git` diffs.
- [dunk](https://github.com/darrenburns/dunk) - Another tool for prettier `git` diffs.
- [fzf-git-worktree](https://github.com/banyan/zsh-fzf-git-worktree) - Manage `git` worktrees with [fzf](https://github.com/junegunn/fzf) integration.
- [gig](https://dev.to/shihanng/gig-a-gitignore-generator-opc) - a CLI `.gitignore` generator
- [git ZSH plugin](https://github.com/davidde/git) - A replacement for the stock oh-my-zsh `git` plugin. Provides quite a few useful aliases and functions that are more consistent in their naming that the relatively unintuitive ones in the stock plugin.
- [git-absorb](https://github.com/tummychow/git-absorb) - Essentially, when your working directory has uncommitted changes on top of draft changesets, you can run `git absorb` and the uncommitted modifications are automagically folded ("absorbed") into the appropriate draft ancestor commits. The command essentially looks at the lines that were modified, finds a commit modifying those lines, and amends that commit to include your uncommitted changes. If the changes can't be made without conflicts, they remain uncommitted. This workflow is insanely useful for things like applying review feedback.
Expand Down
71 changes: 71 additions & 0 deletions bin/git-review-commits
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
#
# bin/git-review-commits
#
# Based on https://jvns.ca/til/fzf-preview-git-commits/

set -o pipefail
if [[ -n "$DEBUG" ]]; then
# shellcheck disable=SC2086
if [[ "$(echo $DEBUG | tr '[:upper:]' '[:lower:]')" == "verbose" ]]; then
set -x
fi
fi

function echo-stderr() {
printf '%s
' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
}

function debug() {
if [[ -n "$DEBUG" ]]; then
echo-stderr "$@"
fi
}

function fail() {
echo-stderr "$1"
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
}

function has() {
# Check if a command is in $PATH
which "$@" > /dev/null 2>&1
}

function check-dependency() {
if ! (builtin command -V "$1" >/dev/null 2>&1); then
fail "missing dependency: can't find $1 in your PATH"
fi
}

function check-dependencies() {
debug "Checking dependencies..."
# shellcheck disable=SC2041
# Placeholders for whatever programs you really need
for dep in "$@"
do
if ! has "$dep"; then
fail "Can't find $dep in your $PATH"
else
debug "- Found $dep"
fi
done
}

# If you need to restrict to a specific os, use
# only-run-on Darwin
# or
# only-run-on Linux

# Placeholders for your script's real dependencies
check-dependencies fzf git grep

commit=${1:-HEAD}
git show --stat=120 --format="" "$commit" | \
grep -E '^\s*\S+.*\|' | \
fzf --ansi \
--disabled \
--bind 'j:down,k:up,q:abort' \
--preview="echo {} | sed 's/|.*//' | xargs -I% git show --color=always $commit -- %" \
--preview-window=right:60%
Loading