Skip to content

Commit 2ee3592

Browse files
committed
add script to crawl history of PDF viewer zathura
1 parent 941955a commit 2ee3592

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

README.md

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Rofi based scripts
22

3-
43
## i3_switch_workspace.sh
54

65
### Usage
76

87
```bash
98
./i3_switch_workspace.sh
109
```
10+
1111
### Screenshot
1212

1313
![I3 Workspace Switcher](i3_switch_workspace.png)
@@ -19,6 +19,7 @@
1919
```bash
2020
./monitor_layout.sh
2121
```
22+
2223
### Screenshot
2324

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

2829
Tries to generate colors from current Gtk+-3.0 theme.
2930
Based on code in Mate-HUD.
31+
32+
### Screenshot
33+
34+
![Monitor Layout](monitor_layout.png)
35+
36+
## zathist.sh
37+
38+
A shell script to fuzzy find (and open) from `rofi` (or `dmenu`) a PDF file in the history of the zathura viewer.
39+
40+
### Installation
41+
42+
To use this script most conveniently:
43+
44+
1. Save this script, say to `~/bin/zathist.sh` by
45+
46+
```sh
47+
mkdir --parents ~/bin &&
48+
curl -fLo https://raw.githubusercontent.com/Konfekt/zathist.sh/master/zathist.sh ~/bin/zathist.sh
49+
```
50+
51+
1. mark it executable by `chmod a+x ~/bin/zathist.sh`,
52+
53+
To launch `zathist.sh` by a global keyboard shortcut, say pressing at the same time the `Microsoft Windows` key and `Z`:
54+
55+
1. install, say, `Xbindkeys` (or `Sxhkd`), (for example, on `openSUSE` by `sudo zypper install xbindkeys` respectively `sudo zypper install sxhkd`)
56+
1. add to `~/.xbindkeysrc` a shortcut that launches `zathist.sh`, say
57+
58+
```sh
59+
"$HOME/bin/zathist.sh"
60+
Mod4 + z
61+
```
62+
63+
1. start `xbindkeys`.
64+
65+
To start `xbindkeys` automatically at login, say on a `KDE` desktop environment, put a file `xbindkeys.sh` reading
66+
67+
```sh
68+
#! /bin/sh
69+
xbindkeys
70+
```
71+
72+
into `~/.config/autostart-scripts/`.
73+
74+
### Configuration
75+
76+
PDFs whose path matches the pattern given by the variable
77+
78+
```sh
79+
IGNORE_REGEX="^${TMPDIR:-/tmp}/\|_cropped\.pdf$"
80+
```
81+
82+
will not be listed.
83+
84+
`zathist.sh` uses rofi in dmenu mode.
85+
Replace at will by dmenu itself and change its command line arguments by the variables
86+
87+
```sh
88+
MENU_ENGINE=-rofi
89+
MENU_ARGS="-dmenu -i -keep-right"
90+
```
91+
92+
To customize the prompt and theme, adapt the variables
93+
94+
```
95+
THEME='
96+
element{ horizontal-align: 0; }
97+
listview {
98+
dynamic: true;
99+
padding: 0px 0px 0px ;
100+
}'
101+
PROMPT='❯ '
102+
```
103+
104+
### Credits
105+
106+
This shell script refines shell code posted on [stackexchange](https://unix.stackexchange.com/questions/467524/open-file-from-history-in-zathura).

zathist.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /bin/sh
2+
#
3+
# Open a PDF file in the history of the zathura viewer from rofi.
4+
#
5+
# Save this script as executable ~/bin/zathist.sh, install Xbindkeys
6+
# (or Sxhkd) and, say, add to ~/.xbindkeysrc the shortcut
7+
#
8+
# "$HOME/bin/zathist.sh"
9+
# Control + Alt + z
10+
#
11+
# This shell script refines https://unix.stackexchange.com/questions/467524/open-file-from-history-in-zathura
12+
13+
# PDFs whose path matches this pattern will not be listed
14+
[ -z "${IGNORE_REGEX:++}" ] &&
15+
IGNORE_REGEX="^${TMPDIR:-/tmp}/\|_cropped\.pdf\|_optimized\.pdf$"
16+
17+
[ -z "${THEME:++}" ] &&
18+
THEME='
19+
element{ horizontal-align: 0; }
20+
listview {
21+
dynamic: true;
22+
padding: 0px 0px 0px ;
23+
}'
24+
PROMPT=${PROMPT:-''}
25+
# uses rofi in dmenu mode; replace by dmenu itself at will
26+
27+
MENU_ENGINE=${MENU_ENGINE:-rofi}
28+
MENU_ARGS="${MENU_ARGS:--dmenu -i -keep-right}"
29+
30+
# regex from https://github.com/lucc/config/blob/d416378290d25b9a61cd8252f7ecf98a294dd80f/rofi/bin/mru.sh#L7
31+
selection=$(
32+
sed -n '/^\[.\+\]$/h;/^time=[0-9]\+$/{x;G;s/^\[\(.\+\)\]\ntime=\([0-9]\+\)$/\2 \1/p}' "${XDG_DATA_HOME:-$HOME/.local/share}/zathura/history" |
33+
sort -nr | cut -d ' ' -f 2- |
34+
grep -v "$IGNORE_REGEX" |
35+
while IFS= read -r f; do [ -f "$f" ] && echo "$f"; done |
36+
sed "s#^${HOME}/#~/#" |
37+
${MENU_ENGINE} ${MENU_ARGS} -theme-str "$THEME" -p "$PROMPT" |
38+
sed "s#^~/#${HOME}/#"
39+
)
40+
[ -r "$selection" ] || exit
41+
nohup zathura "$selection" </dev/null >/dev/null 2>&1 &

0 commit comments

Comments
 (0)