-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_bookmark
executable file
·39 lines (29 loc) · 1.31 KB
/
save_bookmark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
export VISUAL=nvim
export EDITOR="$VISUAL"
term="$(which alacritty) --working-directory $HOME/pCloud -o window.dimensions.columns=110 -o window.dimensions.lines=26 -e"
# term="wezterm-gui --config initial_rows=25 --config initial_cols=100 start --cwd $HOME/pCloud"
editor="$(which nvim)"
# create temp file
file="${TMPDIR}bookmark"
# enter bookmark in the editor
# $term -e $editor $file
$term $editor $file
# read bookmark and delete temp file
bookmark=$(head -n 1 $file)
rm $file
backup_dir="$HOME/Dropbox"
bookmarks="$HOME/.config/bookmarks"
[ ! -f "$bookmarks" ] && mkdir -p "$(dirname $bookmarks)"; touch "$bookmarks"
# check if bookmark has actually a url, otherwise don't save
url=$(echo "$bookmark" | egrep -o 'https?://[^ ]+')
[ -z $url ] && osascript -e 'display notification "⛔ No URL entered!" with title "Bookmarks:"' && exit 1
# check if url is already saved in bookmarks
# match=$(grep -n $url $bookmarks | awk 'FNR <= 1')
match=$(grep -n -E "(^|\s)$url(\s|$)" $bookmarks | awk 'FNR <= 1')
match_index=$(echo $match | cut -d ":" -f 1)
[ -n "$match" ] && $term $editor $bookmarks +$match_index && exit
## Save bookmark
echo "$bookmark" >> $bookmarks
osascript -e 'display notification "👍 Bookmark saved!" with title "Bookmarks:"'
[ -d $backup_dir ] && cp $bookmarks "$backup_dir/bookmarks"