Skip to content

Commit d02a056

Browse files
committed
Add uncommitted changes
Of course I realized _after_ merging the PR Signed-off-by: Joe Block <jpb@unixorn.net>
1 parent ac1552a commit d02a056

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ If you wrote one of these scripts and want it removed from this collection, plea
132132
| `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. |
133133
| `git-pr-fetch` | Joe Block <jpb@unixorn.net> | Fetch PR branches by refspec from one of a repository's remotes. |
134134
| `git-pr-list` | Joe Block <jpb@unixorn.net> | Lists pull requests. Requires `gh`. |
135-
| `git-preview-commits` | Julia Evans'[blog](https://jvns.ca/til/fzf-review-git-commits/) | Use [fzf](https://github.com/junegunn/fzf) topreview commits |
135+
| `git-review-commits` | Julia Evans'[blog](https://jvns.ca/til/fzf-preview-git-commits/) | Use [fzf](https://github.com/junegunn/fzf) topreview commits |
136136
| `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. |
137137
| `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. |
138138
| `git-pruneall` | Ryan Tomayko's dotfiles | Prune branches from specified remotes, or all remotes when no remote is specified. |

bin/git-review-commits

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
#
3+
# bin/git-review-commits
4+
#
5+
# Based on https://jvns.ca/til/fzf-preview-git-commits/
6+
7+
set -o pipefail
8+
if [[ -n "$DEBUG" ]]; then
9+
# shellcheck disable=SC2086
10+
if [[ "$(echo $DEBUG | tr '[:upper:]' '[:lower:]')" == "verbose" ]]; then
11+
set -x
12+
fi
13+
fi
14+
15+
function echo-stderr() {
16+
printf '%s
17+
' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
18+
}
19+
20+
function debug() {
21+
if [[ -n "$DEBUG" ]]; then
22+
echo-stderr "$@"
23+
fi
24+
}
25+
26+
function fail() {
27+
echo-stderr "$1"
28+
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
29+
}
30+
31+
function has() {
32+
# Check if a command is in $PATH
33+
which "$@" > /dev/null 2>&1
34+
}
35+
36+
function check-dependency() {
37+
if ! (builtin command -V "$1" >/dev/null 2>&1); then
38+
fail "missing dependency: can't find $1 in your PATH"
39+
fi
40+
}
41+
42+
function check-dependencies() {
43+
debug "Checking dependencies..."
44+
# shellcheck disable=SC2041
45+
# Placeholders for whatever programs you really need
46+
for dep in "$@"
47+
do
48+
if ! has "$dep"; then
49+
fail "Can't find $dep in your $PATH"
50+
else
51+
debug "- Found $dep"
52+
fi
53+
done
54+
}
55+
56+
# If you need to restrict to a specific os, use
57+
# only-run-on Darwin
58+
# or
59+
# only-run-on Linux
60+
61+
# Placeholders for your script's real dependencies
62+
check-dependencies fzf git grep
63+
64+
commit=${1:-HEAD}
65+
git show --stat=120 --format="" "$commit" | \
66+
grep -E '^\s*\S+.*\|' | \
67+
fzf --ansi \
68+
--disabled \
69+
--bind 'j:down,k:up,q:abort' \
70+
--preview="echo {} | sed 's/|.*//' | xargs -I% git show --color=always $commit -- %" \
71+
--preview-window=right:60%

0 commit comments

Comments
 (0)