Skip to content

Commit

Permalink
add script to crawl history of PDF viewer zathura
Browse files Browse the repository at this point in the history
  • Loading branch information
Konfekt committed Apr 24, 2020
1 parent 787d695 commit 3883621
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
79 changes: 78 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Rofi based scripts


## i3_switch_workspace.sh

### Usage

```bash
./i3_switch_workspace.sh
```

### Screenshot

![I3 Workspace Switcher](i3_switch_workspace.png)
Expand All @@ -19,6 +19,7 @@
```bash
./monitor_layout.sh
```

### Screenshot

![Monitor Layout](monitor_layout.png)
Expand All @@ -27,3 +28,79 @@

Tries to generate colors from current Gtk+-3.0 theme.
Based on code in Mate-HUD.

### Screenshot

![Monitor Layout](monitor_layout.png)

## zathist.sh

A shell script to fuzzy find (and open) from `rofi` (or `dmenu`) a PDF file in the history of the zathura viewer.

### Installation

To use this script most conveniently:

1. Save this script, say to `~/bin/zathist.sh` by

```sh
mkdir --parents ~/bin &&
curl -fLo https://raw.githubusercontent.com/Konfekt/zathist.sh/master/zathist.sh ~/bin/zathist.sh
```

1. mark it executable by `chmod a+x ~/bin/zathist.sh`,

To launch `zathist.sh` by a global keyboard shortcut, say pressing at the same time the `Microsoft Windows` key and `Z`:

1. install, say, `Xbindkeys` (or `Sxhkd`), (for example, on `openSUSE` by `sudo zypper install xbindkeys` respectively `sudo zypper install sxhkd`)
1. add to `~/.xbindkeysrc` a shortcut that launches `zathist.sh`, say

```sh
"$HOME/bin/zathist.sh"
Mod4 + z
```

1. start `xbindkeys`.

To start `xbindkeys` automatically at login, say on a `KDE` desktop environment, put a file `xbindkeys.sh` reading

```sh
#! /bin/sh
xbindkeys
```

into `~/.config/autostart-scripts/`.

### Configuration

PDFs whose path matches the pattern given by the variable

```sh
IGNORE_REGEX="^${TMPDIR:-/tmp}/\|_cropped\.pdf$"
```

will not be listed.

`zathist.sh` uses rofi in dmenu mode.
Replace at will by dmenu itself and change its command line arguments by the variables

```sh
MENU_ENGINE=-rofi
MENU_ARGS="-dmenu -i -keep-right"
```

To customize the prompt and theme, adapt the variables

```
THEME='
element{ horizontal-align: 0; }
listview {
dynamic: true;
padding: 0px 0px 0px ;
}'
PROMPT='❯ '
```
### Credits
This shell script refines shell code posted on [stackexchange](https://unix.stackexchange.com/questions/467524/open-file-from-history-in-zathura).
41 changes: 41 additions & 0 deletions zathist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /bin/sh
#
# Open a PDF file in the history of the zathura viewer from rofi.
#
# Save this script as executable ~/bin/zathist.sh, install Xbindkeys
# (or Sxhkd) and, say, add to ~/.xbindkeysrc the shortcut
#
# "$HOME/bin/zathist.sh"
# Control + Alt + z
#
# This shell script refines https://unix.stackexchange.com/questions/467524/open-file-from-history-in-zathura

# PDFs whose path matches this pattern will not be listed
[ -z "${IGNORE_REGEX:++}" ] &&
IGNORE_REGEX="^${TMPDIR:-/tmp}/\|_cropped\.pdf\|_optimized\.pdf$"

[ -z "${THEME:++}" ] &&
THEME='
element{ horizontal-align: 0; }
listview {
dynamic: true;
padding: 0px 0px 0px ;
}'
PROMPT=${PROMPT:-''}
# uses rofi in dmenu mode; replace by dmenu itself at will

MENU_ENGINE=${MENU_ENGINE:-rofi}
MENU_ARGS="${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} -theme-str "$THEME" -p "$PROMPT" |
sed "s#^~/#${HOME}/#"
)
[ -r "$selection" ] || exit
nohup zathura "$selection" </dev/null >/dev/null 2>&1 &

0 comments on commit 3883621

Please sign in to comment.