#!/usr/bin/env python3 from pdf_data import get_page_pdf from datatypes import * from enum import Enum, auto import subprocess import pydbus import argparse import formatter.typst as typst_fmt parser = argparse.ArgumentParser() parser.add_argument("--section", help="Copy reference to the section title instead of the page number.", action="store_true") class LinkFormat(Enum): TYPST = auto() def clip_copy(txt: str): try: subprocess.run(["xsel", "-ib"], text=True, input=txt) except OSError as e: raise Exception("Please install `xsel`.") from e def copy_ref(ref: Reference, format: LinkFormat) -> None: """Formats Reference and copies it to clipboard.""" match format: case LinkFormat.TYPST: link_txt = typst_fmt.ref(ref) clip_copy(link_txt) def notify(title:str, txt: str) -> None: """Send a text notification.""" bus = pydbus.SessionBus() notifs = bus.get(".Notifications") notifs.Notify("instantref", 0, "dialog-information", title, txt, [], {}, 5000) if __name__ == "__main__": args = parser.parse_args() if args.section: raise NotImplementedError("--section isn't implemented") ref = get_page_pdf() format = LinkFormat.TYPST copy_ref(ref, format) notify("Copied ref", f"{ref.filepath.name} p. {ref.page}")