fixing bookmark_insert script
This commit is contained in:
@@ -3,28 +3,28 @@
|
||||
clipboard_text=$(wl-paste -p)
|
||||
bookmarks_file="$HOME/.local/share/bookmarks/bookmarks"
|
||||
|
||||
# Make sure the bookmark file exists
|
||||
touch "$bookmarks_file"
|
||||
if [ ! -f "$bookmarks_file" ]; then
|
||||
notify-send "Error" "Bookmark file doesn't exist. Please pull the repo."
|
||||
echo "Bookmark file doesn't exist. Please pull the repo." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Trim leading and trailing whitespace from clipboard
|
||||
clipboard_text=$(echo "$clipboard_text" | xargs)
|
||||
|
||||
# Check if clipboard is not empty
|
||||
if [ -n "$clipboard_text" ]; then
|
||||
# Escape special characters for grep
|
||||
escaped_text=$(printf '%s\n' "$clipboard_text" | sed 's:[][\\/.^$*]:\\&:g')
|
||||
|
||||
if grep -Fxq "$escaped_text" "$bookmarks_file"; then
|
||||
# Entry already exists
|
||||
notify-send "Bookmark already exists" "$clipboard_text"
|
||||
# Escape special characters for grep and check for exact match
|
||||
if grep -Fxq "$clipboard_text" "$bookmarks_file"; then
|
||||
notify-send "Bookmark already exists!" "$clipboard_text"
|
||||
else
|
||||
# Append the text to the bookmarks file
|
||||
echo "$clipboard_text" >> "$bookmarks_file"
|
||||
notify-send "Bookmark saved" "$clipboard_text"
|
||||
|
||||
# Run git update script
|
||||
sh "$HOME/.local/bin/bookmark_update"
|
||||
fi
|
||||
else
|
||||
notify-send "No text selected" "Please highlight some text to save as a bookmark."
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user