Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active April 17, 2020 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Konfekt/2815a0eb65b8685e8d4e78de1cbbcec7 to your computer and use it in GitHub Desktop.
Save Konfekt/2815a0eb65b8685e8d4e78de1cbbcec7 to your computer and use it in GitHub Desktop.
zathura MRU: filter in rofi all files viewed in zathura ordered by recency and view selection
#! /bin/sh
#
# Save this script as executable ~/bin/zathist.sh and
# add to ~/.xbindkeysrc the shortcut
#
# "$HOME/bin/zathist.sh"
# Control + Alt + z
#
# PDFs whose path matches this pattern will not be listed
IGNORE_REGEX="^${TMPDIR:-/tmp}/\|_cropped\.pdf$"
# uses rofi in dmenu mode; replace by dmenu itself at will
PROMPT='❯ '
MENU_ENGINE="rofi"
MENU_ARGS='-dmenu -i -keep-right'
# regex from https://github.com/lucc/config/blob/d416378290d25b9a61cd8252f7ecf98a294dd80f/rofi/bin/mru.sh#L7
selection=$(
sed -n '/^\[.\+\]$/h;/^time=[0-9]\+$/{x;G;s/^\[\(.\+\)\]\ntime=\([0-9]\+\)$/\2 \1/p}' "${XDG_DATA_HOME:-$HOME/.local/share}/zathura/history" |
sort -nr | cut -d ' ' -f 2- |
grep -v "$IGNORE_REGEX" |
while IFS= read -r f; do [ -f "$f" ] && echo "$f"; done |
sed "s#^${HOME}/#~/#" |
${MENU_ENGINE} ${MENU_ARGS} -p "$PROMPT" |
sed "s#^~/#${HOME}/#"
)
[ -r "$selection" ] || exit
nohup zathura "$selection" </dev/null >/dev/null 2>&1 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment