blob: bafd74a90f63ce7cb58eeb2a6f29e1a2fda91c0f (
plain) (
blame)
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
64
65
66
67
68
69
70
71
|
#!/usr/bin/env sh
# Description: Show file stats similar to nnn show_stats() output in a pager
# Dependencies: file, stat, pager (PAGER/NNN_PAGER/less)
# Shell: POSIX compliant
entry=${1:-}
dir=${2:-}
if [ -z "$entry" ]; then
printf '%s\n' "No hovered entry provided." >&2
exit 1
fi
case "$entry" in
/*) target=$entry ;;
*)
if [ -n "$dir" ]; then
target=$dir/$entry
else
target=$PWD/$entry
fi
;;
esac
os=$(uname -s 2>/dev/null || printf '%s' unknown)
# Match nnn FILE_MIME_OPTS handling.
file_mime_opts=''
case "$os" in
Darwin)
file_mime_opts='-bIL'
;;
SunOS)
file_mime_opts=''
;;
*)
file_mime_opts='-biL'
;;
esac
# Match nnn stat behavior.
stat_x=0
case "$os" in
FreeBSD|OpenBSD|NetBSD|Darwin|DragonFly)
stat_x=1
;;
esac
tmpfile=$(mktemp "${TMPDIR:-/tmp}/nnn-stats.XXXXXX") || exit 1
trap 'rm -f "$tmpfile"' EXIT HUP INT TERM
{
if [ "$stat_x" -eq 1 ]; then
stat -x "$target"
else
stat "$target"
fi
file -b "$target"
if [ -n "$file_mime_opts" ]; then
file "$file_mime_opts" "$target"
fi
} >"$tmpfile" 2>&1
pager_cmd=${NNN_PAGER:-${PAGER:-less}}
# Allow pager command with options (e.g. "less -R").
# shellcheck disable=SC2086
$pager_cmd "$tmpfile" || cat "$tmpfile"
|