Repository navigation
Expand file tree
/
Copy pathfancydiff
More file actions
executable file
·53 lines (50 loc) · 1.56 KB
/
Copy pathfancydiff
File metadata and controls
executable file
·53 lines (50 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright 2021 Jeremy Brubaker <jbru362@gmail.com>
#
# abstract: pretty diff(1) that is usable as git's core.pager
#
# Requirements: bash for 'exec -a' and $PIPESTATUS
#
filter() {
if command -v delta >/dev/null; then
delta --color-only --diff-so-fancy --paging=never
elif command -v diff-so-fancy >/dev/null; then
diff-so-fancy
else
cat
fi
}
render() {
if [ -t 1 ]; then
filter | LESS="$LESS --RAW-CONTROL-CHARS" less
else
filter
fi
}
if [ $# -gt 0 ]; then
# If there are args, generate diff output and render
/usr/bin/diff -u "$@" | render
elif [ -t 0 ]; then
# No args and no piped input so show diff(1)'s usage error
# ('-a diff' makes the message look like diff's)
exec -a diff /usr/bin/diff
else
# No args but has piped input (e.g., from git) so just render it
render
fi
# Exit with diff's status when run with args
exit "${PIPESTATUS[0]}"