#!/bin/sh # hh-recent-pipemenu - Openbox "Recent Files" pipe menu (GTK-free) # # Loosely modeled on CrunchBang++'s cbpp-recent-files-pipemenu # (github.com/CBPP/cbpp-pipemenus), but that one parses GTK's # ~/.local/share/recently-used.xbel, which nothing on Hammerhead writes # (no GTK). Instead: find(1) over $HOME for recently-modified # docs/images, opened with the matching viewer. # # Usage: max_entries=12 home="${HOME:-/root}" xml_escape() { printf '%s' "$1" | sed \ -e 's/&/\&/g' \ -e 's//\>/g' \ -e 's/"/\"/g' } viewer_for() { case "$1" in *.pdf) echo "hh-pdf" ;; *.png|*.jpg|*.jpeg|*.gif|*.bmp) echo "hh-images" ;; *) echo "xnedit" ;; esac } printf '\n' count=0 find "$home" -maxdepth 3 -type f \ \( -iname '*.pdf' -o -iname '*.txt' -o -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' \) \ -mtime -14 -print 2>/dev/null | while IFS= read -r f; do viewer="$(viewer_for "$f")" label="$(xml_escape "${f##*/}")" path="$(xml_escape "$f")" printf ' \n' "$label" printf ' %s %s\n' "$viewer" "$path" printf ' \n' count=$((count + 1)) [ "$count" -ge "$max_entries" ] && break done printf '\n'