|
Maciej Janicki's website |
2020-09-20
desktop
dmenu
shell
Having all PDFs just a few keystrokes awayI tend to have a lot of PDF files on my computer: books, science papers, presentations… I often need to quickly open one of them: check a theoretical detail in a book related to what I’m doing or a reference in a paper I’m reading. With the help of dmenu and a short shellscript, I have found a way to make this process as quick and unintrusive as possible. dmenu: a quick introductiondmenu is a fantastic program that serves only the purpose of “choosing one option out of a list of possibilities”. It is very similar to fzf that I’ve mentioned before, but operating in a graphical window manager instead of the text terminal. Here’s a minimal example: This will show the following menu on the top of the screen:
Once you start typing, the selection will be narrowed down to the entries containing the typed string. The chosen item will be printed on standard output. The basic solutionIn our case, the entries in the list are going to be paths of PDF files on the
system. I store all my documents in the directory Let’s combine this with dmenu to be able to choose one file from the list: The parameter The output of the command is the chosen file. The only missing part now is to pass the filename to your PDF reader of choice. Mine is zathura, so I do the following: And here’s the result:
Just save it to a shellscript file, bind it to a key in your window manager and there you go! …except…If you’re a purist like me, you may be disturbed be the need to call the The condition in the first line makes use of two tests: It is easy to generalize this script to handle different directories, file extensions and opening programs (movies, images, what have you). This will be left as an exercise for the reader. | |
| Powered by Jekyll. Copyright © Maciej Janicki 2019-2020. Licensed under CC BY. | |