-
Notifications
You must be signed in to change notification settings - Fork 39
/
git-find-ignored-files
executable file
·63 lines (53 loc) · 1.17 KB
/
git-find-ignored-files
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
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
#
# Find all files present in the index and working tree ignored by .gitignore.
#
# Usage:
# git-find-ignored-files [-s | --sort-by-size] [--help]
#
# Author: Patrick Lühne, https://www.luehne.de/
#
function print_help
{
grep "^# Usage" < "$0" | cut -c 3-
}
if [[ $# -gt 1 ]]
then
print_help
exit 1
fi
case "$1" in
-h|--help)
print_help
exit 0
;;
-s|--sort-by-size)
;;
*)
if [[ $# -gt 0 ]]
then
(>&2 echo "error: unknown option “$1”")
print_help
exit 1
fi
;;
esac
# Find all ignored files
files=$(git ls-files --ignored --exclude-standard)
# Stop if no ignored files were found
if [[ -z $files ]]
then
(>&2 echo "info: no ignored files in working tree or index")
exit 0
fi
# Compute the file sizes of all these files
file_sizes=$(echo "$files" | tr '\n' '\0' | xargs -0 du -sh)
# Obtain the origins why these files are ignored
gitignore_origins=$(echo "$files" | git check-ignore --verbose --stdin --no-index)
# Merge the two lists into one
command="join -1 2 -2 2 -t $'\t' -o 1.1,1.2,2.1 <(echo \"$file_sizes\") <(echo \"$gitignore_origins\")"
if [[ $1 =~ ^-s|--sort-by-size$ ]]
then
command="$command | sort -h"
fi
eval "$command"