-
Notifications
You must be signed in to change notification settings - Fork 1
/
mutt-trans
executable file
·50 lines (42 loc) · 949 Bytes
/
mutt-trans
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
#!/bin/sh
#
# NAME
#
# mutt-trans - helper script to pipe message thru trans(1)
#
# SYNOPSIS
#
# mutt-trans < .../path/to/message
#
# DEPENDENCIES
#
# less(1), md5sum(1), mktemp(1), and trans(1)
#
: ${PAGER:=less}
tmpfile="$(mktemp -u)"
trap 'rm -rf "$tmpfile" >/dev/null 2>&1' EXIT
trap 'exit 2' HUP INT QUIT TERM
cache="$HOME/.cache/mutt/trans"
mkdir -p "$cache"
cat >"$tmpfile"
out="$cache/$(md5sum "$tmpfile" | cut -d ' ' -f 1)"
[ -f "$out" ] || {
echo >&2 "${0##*/}: translating..."
awk '
BEGIN { visible = 0 }
/^(Subject|Date|From|To|Cc|Bcc|Sender):/ { print }
/^\s*$/ { visible = 1 }
{
if (visible)
print
}
' "$tmpfile" \
| trans \
-brief \
-no-autocorrect \
-no-theme \
-no-browser \
-no-warn \
-output "$out"
}
exec "$PAGER" "$out"