2 # aur-view - inspect package files
3 [[ -v AUR_DEBUG
]] && set -o xtrace
6 XDG_DATA_HOME
=${XDG_DATA_HOME:-$HOME/.local/share}
7 AUR_VIEW_DB
=${AUR_VIEW_DB:-$XDG_DATA_HOME/aurutils/$argv0}
8 PS4
='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
11 log_fmt
='diff' log_args
=() excludes
=() patch=1 prefix
=0
14 # shellcheck disable=SC2155
15 local str
=$
(printf '%s,' "$@")
16 printf '%s' "${str%,}"
20 if [[ ! -v AUR_DEBUG
]]; then
23 printf >&2 'AUR_DEBUG: %s: temporary files at %s\n' "$argv0" "$tmp"
28 plain
>&2 'usage: %s [--format] <package...>' "$argv0"
33 opt_long
=('format:' 'arg-file:' 'revision:' 'no-patch' 'confirm' 'exclude:' 'prefix')
34 opt_hidden
=('dump-options')
36 if opts
=$
(getopt
-o "$opt_short" -l "$(args_csv "${opt_long[@]}" "${opt_hidden[@]}")" -n "$argv0" -- "$@"); then
42 unset queue revision prefix
53 printf >&2 '%s: invalid --format option: %s' "$argv0" "$1"
57 AUR_CONFIRM_PAGER
=1 ;;
65 shift; excludes
+=("$1") ;;
67 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
68 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
79 # shellcheck disable=SC2174
80 mkdir -pm 0700 -- "${TMPDIR:-/tmp}/aurutils-
$UID"
81 tmp=$(mktemp -d --tmpdir "aurutils-
$UID/$argv0.XXXXXXX
")
84 # Directory for git checksums (revisions viewed by the user, #379)
85 mkdir -p -- "$AUR_VIEW_DB"
87 # Take input from a file instead of redirecting stdin (#871)
89 if [[ -v queue ]]; then
92 while read -ru "$fd"; do
93 [[ $REPLY ]] && packages+=("$REPLY")
100 if (( ! ${#packages[@]} )); then
101 printf >&2 "there is nothing to
do"
105 # Link build files in the queue (absolute links)
106 for pkg in "${packages[@]}"; do
107 [[ $pkg ]] && printf '%s\0' "$
(pwd -P)/$pkg"
108 done | xargs -0 ln -t "$tmp" -s --
110 # Retrieve last viewed revisions
113 for pkg in "${packages[@]}"; do
114 git() { command git -C "$pkg" "$@
"; }
116 # Ensure every directory is a git repository (--continue)
117 if head=$(git rev-parse "${revision:-HEAD}"); then
120 printf >&2 '%s: %s: revision %s not found\n' "$argv0" "$pkg" "${revision:-HEAD}"
125 if (( prefix )); then
126 path_args=(--src-prefix="$pkg/" --dst-prefix="$pkg/")
129 if [[ -f $AUR_VIEW_DB/$pkg ]] && read -r view < "$AUR_VIEW_DB/$pkg"; then
130 # Check if hash points to an existing object
131 if ! git cat-file -e "$view"; then
132 printf >&2 '%s: %s: invalid git revision\n' "$argv0" "$AUR_VIEW_DB/$pkg"
136 if [[ $view != "$head" ]]; then
137 git --no-pager "$log_fmt" --stat "${log_args[@]}" "${path_args[@]}" \
138 "$view..
$head" -- "${excludes[@]}" > "$tmp/$pkg.
$log_fmt"
141 elif [[ -f $AUR_VIEW_DB/$pkg ]]; then
142 printf >&2 '%s: %s: failed to read revision\n' "$argv0" "$pkg"
148 # Begin file inspection
149 if [[ -v AUR_PAGER ]]; then
150 # shellcheck disable=SC2086
151 command -- $AUR_PAGER "$tmp"
153 # Use an additional prompt for file managers with no support
154 # for exit codes greater 0 (#673)
155 if [[ -v AUR_CONFIRM_PAGER ]] && (( AUR_CONFIRM_PAGER )); then
156 read -rp $'Press Return to continue or Ctrl+d to abort\n'
159 elif type -P vifm >/dev/null; then
160 # Show hidden directories (.git)
163 { # Print patch files
164 for f in "$tmp"/*; do
165 [[ -f $f ]] && printf '%s\0' "$f"
168 # Print build directories (non-empty) in dependency order
169 for d in "$tmp"/*/; do
170 printf '%s\0' "$d" "$d"/*
172 # Avoid directory prefix in printed paths (#452)
173 } | env -C "$tmp" vifm -c 'set vifminfo=' -c 'view!' -c '0' -
176 printf >&2 '%s: no viewer found, please install vifm or set AUR_PAGER\n' "$argv0"
180 # Update gitsums (viewer exited successfully)
181 for pkg in "${packages[@]}"; do
182 printf '%s\n' "${heads[$pkg]}" > "$AUR_VIEW_DB/$pkg"