Skip to content

Instantly share code, notes, and snippets.

@oasido
Created November 9, 2024 11:42
Show Gist options
  • Save oasido/42e14b58a2dc791a98b58efd86b2df5b to your computer and use it in GitHub Desktop.
Save oasido/42e14b58a2dc791a98b58efd86b2df5b to your computer and use it in GitHub Desktop.
okular save/restore session
#!/usr/bin/env bash
# Save and restore Okular sessions
set -e
dump() {
for fd in /proc/$(ps -C okular -o pid= | sed -e's/\s//g')/fd/*; do
readlink "$fd"
done | grep '.pdf'
}
save() {
dump >~/.okular-session
}
# we use xdg-open instead of okular so that
# it will open the files in new tabs instead
# of new windows
restore() {
while read file; do
xdg-open "$file"
done <~/.okular-session
}
case "$1" in
save | restore)
$1
;;
*)
echo "valid commands: save, restore" >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment