add pdf bookmarks script

This commit is contained in:
Salim Zaidi 2023-07-03 11:48:48 +01:00
parent 4d97e6e309
commit 290141c878
2 changed files with 45 additions and 0 deletions

42
config/scripts/bookmark_pdf.sh Executable file
View file

@ -0,0 +1,42 @@
#!/bin/bash
# Set the path to the PDF bookmarks file
bookmarks_file="/home/$USER/.config/pdf_bookmarks.txt"
temp_file="/home/$USER/.config/pdf_bookmarks.tmp"
# Get the title of the active PDF file
title=$(xdotool getactivewindow getwindowname)
# Remove leading/trailing whitespaces from the title
title=$(echo "$title" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
# Check if the bookmarks file exists, otherwise create it
if [ ! -f "$bookmarks_file" ]; then
touch "$bookmarks_file"
fi
# Prompt the user to enter the page number using rofi
page=$(rofi -dmenu -p "Enter the page number for $title:")
# If the user cancels or leaves the page number empty, exit the script
if [ -z "$page" ]; then
exit
fi
# Check if the PDF file is already bookmarked
existing_bookmark=$(grep -F "$title:" "$bookmarks_file")
# If the PDF file is already bookmarked, update the page number
if [ -n "$existing_bookmark" ]; then
# Create a temporary file and remove the original bookmark entry
grep -v "^$title:" "$bookmarks_file" > "$temp_file"
else
# If it's a new PDF file, copy the existing bookmarks to the temporary file
cp "$bookmarks_file" "$temp_file"
fi
# Append the updated bookmark entry to the temporary file
echo "$title:$page" >> "$temp_file"
# Replace the original file with the updated version
mv "$temp_file" "$bookmarks_file"

View file

@ -25,6 +25,9 @@ alt + y
alt + shift + y alt + shift + y
sudo /home/zed/.config/scripts/yt_blocker.sh sudo /home/zed/.config/scripts/yt_blocker.sh
alt + z
source ~/.config/scripts/bookmark_pdf.sh
alt + p alt + p
pavucontrol pavucontrol