Last active
March 4, 2021 16:26
-
-
Save kidpixo/6faaf4404260be21040951cdfca97dcb to your computer and use it in GitHub Desktop.
Open file from zathura history with rofi, checking if files exist. (Bash>=4.4 for array functions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# see https://unix.stackexchange.com/questions/467524/open-file-from-history-in-zathura | |
# save filepaths in history to array, reverse order | |
readarray -t Data < <(grep -o '/.*\.[[:alpha:]]\{,3\}' ~/.local/share/zathura/history | tac) | |
# loop and unset not existing files | |
for i in "${!Data[@]}" | |
do | |
if ! [ -e "${Data[$i]}" ]; then | |
# echo "${Data[$i]} does not exist." | |
unset 'Data[$i]' | |
# else | |
## Add substitition $HOME with ~ , really slow | |
# Data[$i]=$(echo ${Data[$i]} | sed "s#$HOME#~#") | |
# # echo "${Data[$i]} exists." | |
fi | |
done | |
selected=$( ( IFS=$'\n'; echo "${Data[*]}" ) | rofi -width 95 -dmenu -i -markup-rows) | |
# exit if nothing is selected | |
[[ -z $selected ]] && exit | |
# prevent opening not existing file | |
if [ -f "$selected" ]; then | |
# echo "$selected exists." | |
zathura "$selected" | |
else | |
# echo "$selected does not exist." | |
exit | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment