From 10420e0f99af0d094bef9d04da9bd5aa80b7e04e Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Tue, 13 Aug 2024 22:29:07 +0200 Subject: [PATCH] gitdiffdir: Take diff options. --- gitdiffdir/gitdiffdir | 48 +++++++++++++++++++++++++++++++++++-------- vid/vid | 2 +- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/gitdiffdir/gitdiffdir b/gitdiffdir/gitdiffdir index 8d24635..1f4e67e 100755 --- a/gitdiffdir/gitdiffdir +++ b/gitdiffdir/gitdiffdir @@ -10,17 +10,20 @@ gitdiffdir - git diff, but between two dirs in different repositories =head1 SYNOPSIS -gitdiffdir dir1 dir2 +B [I] I I =head1 DESCRIPTION -B only looks at tracked files. B +B only looks at tracked files. B I includes all untracked files. -B tries to simulate B but on two dirs in -different repositories. +B tries to simulate B by only looking at tracked +files but on two dirs in different repositories. +=head1 OPTIONS + +B passes options to B. Default: B<-Naur> =head1 EXAMPLES @@ -32,6 +35,10 @@ Diff dirs with the different names: gitdiffdir myproject/mydir1 myoldproject/mydir2 +Ignore new files: + + gitdiffdir -aur myproject/mydir1 myoldproject/mydir2 + =head1 AUTHOR @@ -69,10 +76,34 @@ B =cut -dirA="$1" -dirB="$2" +diff_options=() +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 # STDOUT = terminal # use less @@ -82,6 +113,5 @@ stdout() { fi } - 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 diff --git a/vid/vid b/vid/vid index 32c192f..fd83a35 100755 --- a/vid/vid +++ b/vid/vid @@ -5,7 +5,7 @@ =head1 NAME -vid - Play videos matching strings +vid - Play videos matching strings in descending order of size =head1 SYNOPSIS