diff --git a/config/scripts/bookmark_pdf.sh b/config/scripts/bookmark_pdf.sh new file mode 100755 index 0000000..a3b7999 --- /dev/null +++ b/config/scripts/bookmark_pdf.sh @@ -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" diff --git a/config/sxhkd/sxhkdrc b/config/sxhkd/sxhkdrc index 8eec630..03c9cb3 100755 --- a/config/sxhkd/sxhkdrc +++ b/config/sxhkd/sxhkdrc @@ -25,6 +25,9 @@ alt + y alt + shift + y sudo /home/zed/.config/scripts/yt_blocker.sh +alt + z + source ~/.config/scripts/bookmark_pdf.sh + alt + p pavucontrol