14

zathura is my default PDF reader. Some files cause it trouble though, and in such cases I run

:exec acroread $FILE

which automatically opens the same file with Acrobat Reader.

How do I add a key shortcut to the zathura configuration file (~/.config/zathura/zathurarc) to do that?

Felix Bou
  • 141
  • 1
  • 5

4 Answers4

11

I recently bumped against a similar problem and, for future reference, here is a workaround:

map <C-o> focus_inputbar ":exec acroread $FILE"

This will map ctrl+o (or whichever your key is) to open the input bar you would normally open with : and input there that text. You can then press Enter to launch the command. This is far from ideal and still requires a two-key press, but surely faster than writing all the command by hand.

Tom Hale
  • 28,728
  • 32
  • 139
  • 229
CarloDePieri
  • 111
  • 1
  • 4
  • Is there something like $FILE or % in zathura which brings back the directory (not the filename)? – SddS May 21 '18 at 09:31
  • @SdidS not to my knowledge, but the zathura documentation is quite lacking (they also have an open issue regarding this here: [gitlab](https://git.pwmt.org/pwmt/zathura/issues/12)). Anyway: everything after exec is executed by zathura so you could probably try to pass the filename to a script that will then extract the folder from the $FILE and do what you need it to do. If you need something more specific I suggest trying to open an issue on the gitlab I linked above. – CarloDePieri May 22 '18 at 13:30
  • `@CarloDePieri`, Thanks I've asked it [here](https://unix.stackexchange.com/questions/445089/how-to-get-current-document-directory-path-from-zathura) and came up with the same solution as you said. – SddS May 22 '18 at 19:44
9

A slight improvement on the answer offered by CarloDePieri might be this:

map <C-o> feedkeys ":exec acroread $FILE<Return>"

This avoids the second keypress.

Tom Hale
  • 28,728
  • 32
  • 139
  • 229
  • Note that this will store the line into the input history, but the other methods does not work when the file name contain `"`. – user202729 Jan 21 '23 at 03:16
3

I agree that would be seriously useful, but you can't currently do this.

In the source code, the input-bar exec command mapping is here in config.c. However, the shortcut mappings (starting here) which seem to define what functions can be referred to from the configs don't mention exec. The code isn't structured to easily mix "command" functions and "shortcut" functions yet...

The developers have a page with methods to contact them.

  • (this answer is outdated, now there's a way) the source code has moved to https://github.com/pwmt/zathura/blob/81e541e3f0554541548be5aa846e4845b9e6fb9a/zathura/config.c#L521 . – user202729 Jan 21 '23 at 03:31
1

While trying to create a mapping that puts the path of the current PDF on the system clipboard, I realized that I have to wrap the whole command in bash -c "...":

map y focus_inputbar ":exec bash -c \"printf \\\"$FILE\\\" | xclip -selection c\""

For Wayland, the syntax would be:

map y focus_inputbar ":exec bash -c \"printf \\\"$FILE\\\" | wl-copy\""

Otherwise the command won't do anything.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
  • Similar to https://unix.stackexchange.com/a/606432/296692, this does not support file names contain `"` or ``\``. A better approach would be to use the `feedkeys` approach combined with writing a bash script to manipulate the file name, if bash is needed (for piping for example). – user202729 Jan 21 '23 at 03:14