Skip to content

Commit

Permalink
Add helpers using qlview from mutt.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmmr committed Feb 25, 2024
1 parent adca94d commit 0db42c4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.3-1 | 2024-02-25 08:48:09 +0100

* Add helpers using qlview from mutt.

0.3 | 2024-02-10 13:11:55 +0100

* Notarize distribution.
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ zip:
rm -rf build/dist
mkdir -p build/dist
cp -R build/Release/qlview build/dist
cp -R mutt build/dist
cd build/dist && zip -r ../qlview-$(VERSION).zip *
ls build/*.zip | sed 's/^/> /'

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ Run it from the command line:
If you execute `qlview` without any arguments, it'll open an empty
window where you can drag a document into.

## Mutt integration

To use `qlview` with [mutt](http://www.mutt.org), there's a helper
script
[mutt-qlview](https://github.com/rsmmr/qlview/blob/main/mutt/mutt-qlview)
coming with the distribution. Put both that script and `qlview` itself
into your `PATH` and then add [these mailcap
entries](https://github.com/rsmmr/qlview/blob/main/mutt/mailcap) to
your mutt configuration; see [mutt's
manual](http://www.mutt.org/doc/manual/#mailcap) for more on that.

You can also add the following to your `.muttrc` to quickly open the
first HTML attachment in `qlview`:

```
macro index,pager V <view-attachments>/html\n<view-mailcap><quit>
```

## Feedback

Feel free to open issues or pull requests.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3
0.3-1
6 changes: 6 additions & 0 deletions mutt/mailcap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
application/*; mutt-quicklook %s
audio/*; mutt-quicklook %s
image/*; mutt-quicklook %s
text/*; mutt-quicklook %s
text/html; mutt-quicklook %s; nametemplate=%s.html;
video/*; mutt-quicklook %s
37 changes: 37 additions & 0 deletions mutt/mutt-qlview
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
#
# Wrapper around qlview for use from mutt's mailcap. qlview must be in same
# path as this script, or inside $PATH. The script initially retain a copy of
# the file being viewed, which will it will delete when running for the 1st
# time day later, or when run again with the same file name.

prog=$0

usage() {
echo "usage: $(basename "${prog}") <file>"
exit 1
}

error() {
echo "$(basename "${prog}"): $*" >&2
exit 1
}

qlview="$(cd "$(dirname "$0")" && pwd)/qlview"
test -f "${qlview}" -a -x "${qlview}" || qlview="$(command -v qlview 2>/dev/null)"

test -n "${qlview}" || error "qlview not found"
test $# -eq 1 || usage

file="$1"
test -f "${file}" || error "no file '${file}'"

tmpdir="${HOME:?}/.cache/mutt"
mkdir -m 0700 -p "${tmpdir}"
find "${tmpdir}" -maxdepth 1 -type f -mtime +1d -delete

tmpfile="${tmpdir}/$(basename "${file}")"
mkdir -p "${tmpdir}"
cp -f "${file}" "${tmpfile}"

nohup "${qlview}" "${tmpfile}" >/dev/null 2>&1 </dev/null &
2 changes: 2 additions & 0 deletions mutt/muttrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Drectly open first HTML attachment with qlview from index and pager.
macro index,pager V <view-attachments>/html\n<view-mailcap><quit>
2 changes: 1 addition & 1 deletion qlview/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<key>CFBundleName</key>
<string>qlview</string>
<key>CFBundleVersion</key>
<string>0.3</string>
<string>0.3-1</string>
</dict>
</plist>

0 comments on commit 0db42c4

Please sign in to comment.