add AUR.pm
[aurutils.git] / examples / view-delta
blob32399931c4c87355c1d68b57bc70fac23913b9d6
1 #!/bin/bash
2 [[ -v AUR_DEBUG ]] && set -o xtrace
3 set -o errexit
4 shopt -s extglob
6 # Helper function to take complements of pkgbase arrays
7 filter_packages() { grep -Fxvf <(printf '%s\n' "$@") -; }
9 # Directory with diffs and PKGBUILD subdirs
10 cd "${1:-/dev/null}"
11 diffs=(@(*.diff|*.log))
12 pkgbases=(*/)
13 pkgbases=("${pkgbases[@]%/}")
15 # Show diffs in 2 panes
16 if [[ -f ${diffs[0]} ]]; then
17 cat "${diffs[@]}" | delta --diff-so-fancy --paging=always --line-numbers --navigate
19 # Remove diffs from remaining targets (new or unchanged dirs)
20 mapfile -t pkgbases < <(
21 printf '%s\n' "${pkgbases[@]}" | filter_packages "${diffs[@]%%.*}")
22 fi >&2
24 # Show remaining targets in a concatenated fashion
25 if (( ${#pkgbases[@]} )); then
26 # Only print files in the git repository
27 find -L "${pkgbases[@]}" -prune -exec sh -c 'git -C {} ls-files -z | env -C {} xargs -0r realpath -z' \; |
28 grep -Ezv '.SRCINFO|.gitignore' | xargs -0r bat --paging=always
29 fi >&2
31 # Show an exit prompt
32 read -rp $'Press Return to continue or Ctrl+d to abort\n'