From 97f968a30e7dc28f6d99bfbaae8a4aeefb6ad525 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 23 Jan 2026 12:48:30 +0100 Subject: added all of my scripts --- bookmarkthis | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 bookmarkthis (limited to 'bookmarkthis') diff --git a/bookmarkthis b/bookmarkthis new file mode 100755 index 0000000..22aff66 --- /dev/null +++ b/bookmarkthis @@ -0,0 +1,61 @@ +#!/bin/sh +set -eu + +file="$HOME/.snippets" +mkdir -p "$(dirname "$file")" +touch "$file" + +# wybierz JEDNO: +bookmark="$(xclip -o -selection primary 2>/dev/null || true)" # zaznaczenie myszką +# bookmark="$(xclip -o -selection clipboard 2>/dev/null || true)" # Ctrl+C + +# usuń końcowe nowe linie (częste przy kopiowaniu) +bookmark="$(printf '%s' "$bookmark" | sed -e 's/[[:space:]]\+$//')" + +if [ -z "$bookmark" ]; then + notify-send "No string highlighted!" "Please select/copy a string to bookmark" + exit 1 +fi + +# literalne dopasowanie całej linii +if grep -Fxq -- "$bookmark" "$file"; then + notify-send "Oops" "Already Bookmarked!" + exit 0 +fi + +# edycja w dmenu: domyślnie pokazuje już wartość +bookmarkEdit="$(printf '%s' "$bookmark" | dmenu -p "Edit bookmark:")" + +# jeśli ESC albo pusto -> użyj oryginału +if [ -z "${bookmarkEdit:-}" ]; then + out="$bookmark" +else + out="$bookmarkEdit" +fi + +# zapisz jako nową linię +printf '%s\n' "$out" >> "$file" +notify-send "Bookmark added!" "$out is now saved to the file" + +# bookmark="$(xclip -o)" +# file="${HOME}/.snippets" +# +# if [ -z "$bookmark" ] +# then +# notify-send "No string highlighted!" "Please select a string to bookmark" +# exit 1 +# else +# if grep -q "^$bookmark$" "$file"; then +# notify-send "Oops" "Already Bookmarked!" +# else +# bookmarkEdit=$(:|dmenu -p "Make changes to the bookmark: $bookmark" & sleep 0.1 && xdotool type $bookmark) +# if [ -z "$bookmarkEdit" ] +# then +# notify-send "Bookmark added!" "$bookmark is now saved to the file" +# echo "$bookmark" >> $file +# else +# notify-send "Bookmark added!" "$bookmarkEdit is now saved to the file" +# echo "$bookmarkEdit" >> "$file" +# fi +# fi +# fi -- cgit v1.3