nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

yank-to-todo (735B)


      1 #!/usr/bin/env bash
      2 
      3 todo_file=~/.nb/notes/todo.txt
      4 
      5 if [[ -n "$1" ]]; then
      6 	url="$1"
      7 else
      8 	wl_focused_title="$(wlr-river-title)"
      9 	if [[ "$wl_focused_title" == *"Mozilla Firefox"* ]]; then
     10 		/usr/bin/wtype "yy" && sleep 0.5
     11 		url=$(wl-paste 2>/dev/null)
     12 	else
     13 		notify-send -u critical "Error" "Focused window is not a web browser ($wl_focused_title)"
     14 		exit 1
     15 	fi
     16 fi
     17 
     18 if [[ -z "$url" ]]; then
     19 	notify-send "No url found"
     20 	exit 1
     21 fi
     22 
     23 if [[ ! "$url" =~ ^https?:// ]]; then
     24 	notify-send "Invalid format" "$url"
     25 	exit 1
     26 fi
     27 
     28 tmp=$(mktemp)
     29 printf "%s\ntodo: %s\n\n" "$(date --rfc-3339=s)" "$url" > "$tmp"
     30 cat "$todo_file" >> "$tmp"
     31 if mv "$tmp" "$todo_file"; then
     32 	notify-send "Saved" "$url"
     33 else
     34 	notify-send -u critical "Error" "$url"
     35 fi