gitdiffdir: Take diff options.

This commit is contained in:
Ole Tange 2024-08-13 22:29:07 +02:00
parent f0dd01f79a
commit 10420e0f99
2 changed files with 40 additions and 10 deletions

View file

@ -10,17 +10,20 @@ gitdiffdir - git diff, but between two dirs in different repositories
=head1 SYNOPSIS =head1 SYNOPSIS
gitdiffdir dir1 dir2 B<gitdiffdir> [I<diff options>] I<dir1> I<dir2>
=head1 DESCRIPTION =head1 DESCRIPTION
B<git diff> only looks at tracked files. B<git diff dir1 dir2> B<git diff> only looks at tracked files. B<git diff> I<dir1 dir2>
includes all untracked files. includes all untracked files.
B<gitdiffdir> tries to simulate B<git diff> but on two dirs in B<gitdiffdir> tries to simulate B<git diff> by only looking at tracked
different repositories. files but on two dirs in different repositories.
=head1 OPTIONS
B<gitdiffdir> passes options to B<diff>. Default: B<-Naur>
=head1 EXAMPLES =head1 EXAMPLES
@ -32,6 +35,10 @@ Diff dirs with the different names:
gitdiffdir myproject/mydir1 myoldproject/mydir2 gitdiffdir myproject/mydir1 myoldproject/mydir2
Ignore new files:
gitdiffdir -aur myproject/mydir1 myoldproject/mydir2
=head1 AUTHOR =head1 AUTHOR
@ -69,10 +76,34 @@ B<git>
=cut =cut
dirA="$1" diff_options=()
dirB="$2" others=()
stdout() { # Loop through all arguments
while [[ $# -gt 0 ]]; do
case $1 in
-*) diff_options+=("$1") ;; # Add to options array if it starts with -
*) others+=("$1") ;; # Add to others array if it doesn't start with -
esac
shift # Shift to the next argument
done
if [ ${#diff_options[@]} -eq 0 ]; then
# Default: diff -Naur
diff_options+=("-Naur")
fi
dirA="${others[0]}"
dirB="${others[1]}"
# Remove all trailing slashes
while [[ "$dirA" == */ ]]; do
dirA="${dirA%/}"
done
while [[ "$dirB" == */ ]]; do
dirB="${dirB%/}"
done
less_or_cat() {
if [ -t 1 ] ; then if [ -t 1 ] ; then
# STDOUT = terminal # STDOUT = terminal
# use less # use less
@ -82,6 +113,5 @@ stdout() {
fi fi
} }
parallel -0 'cd {} && git ls-files' ::: "$dirA" "$dirB" | sort -u | parallel -0 'cd {} && git ls-files' ::: "$dirA" "$dirB" | sort -u |
parallel -q diff -Naur "$dirA"/{} "$dirB"/{} | stdout parallel -q diff "${diff_options[@]}" "$dirA"/{} "$dirB"/{} | less_or_cat

View file

@ -5,7 +5,7 @@
=head1 NAME =head1 NAME
vid - Play videos matching strings vid - Play videos matching strings in descending order of size
=head1 SYNOPSIS =head1 SYNOPSIS