-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmarker.ind
executable file
·82 lines (76 loc) · 2.47 KB
/
bookmarker.ind
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# Browser independent version
urlfile=~/.local/share/webbookmarks
separator='<' #"<" | ">" | "#" | "%" | <"> # one of these
bak="$HOME/.local/share/bak"
default_se='https://www.google.com/search?q='
#default_se='https://duckduckgo.com/?q='
#default_se='https://www.startpage.com/do/dsearch?query='
#default_se='https://www.bing.com/search?q='
help() {
while IFS= read -r line; do
printf "%s\n" "$line"
done <<-EOF
USO:
-a añadir marcador
-d eliminar entrada
-e editar archivo de marcadores
-H historial de búsqueda (solo firefox)
-b crear un backup del archivo de marcadores
EOF
}
[ -n "$1" ] && case $1 in
-a)
printf '%s' "pon nombre del marcador: " \
&& read -r nombre && printf '%s' "pon url: " \
&& read -r url && echo "$nombre $separator|$url" >> $urlfile;;
-d)
urls=$(fzf --cycle --reverse --prompt='eliminar entrada: ' -m < $urlfile) \
&& printf '%s\n' "$urls" | while IFS= read -r line
do
sed -i "/$line/d" "$urlfile" && notify-send "$line eliminada"
done;;
-e)
"$EDITOR" "$urlfile" 2>/dev/null || xdg-open "$urlfile" ;;
-H)
proc=$(pidof $BROWSER)
if [ -z "$proc" ]; then
a="$(sqlite3 ~/.mozilla/firefox/*.default-*/places.sqlite \
'SELECT * FROM moz_places;' | tail -n 500 | tac | dmenu -c -l 30 )" \
&& [ -n "$a" ] && setsid -f "$BROWSER" $(echo $a| cut -d'|' -f2)
else
if [ ! -f /tmp/places.sqlite ]; then
cp ~/.mozilla/firefox/*.default-*/places.sqlite /tmp/
a="$(sqlite3 /tmp/places.sqlite \
'SELECT * FROM moz_places;' | tail -n 500 \
| tac | dmenu -c -l 30)" && [ -n "$a" ] \
&& setsid -f "$BROWSER" $(echo $a| cut -d'|' -f2)
else
a="$(sqlite3 /tmp/places.sqlite \
'SELECT * FROM moz_places;' | tail -n 500 | tac \
| dmenu -l 30)" && [ -n "$a" ] \
&& setsid -f "$BROWSER" $(echo $a| cut -d'|' -f2)
fi
fi
;;
-b)
[ ! -d $bak ] && mkdir -p $bak
cp $urlfile $bak/bookmarker.$(date +%Y%m%d%H%M%S) \
&& notify-send -u low "bakup nuevo en $bak" ;;
*)
help ;;
esac
[ -n "$1" ] && exit
urls="$(grep -v '^#' $urlfile | column -s"$separator" -t \
| dmenu -i -l 20 -sb '#898818' -fn 'Mono' -p 'marcadores web:')" || exit 1
if [ -n "$(echo $urls | grep "|")" ]; then
url=$(printf '%s\n' "$urls" | cut -d"|" -f2- |tr ' ' '+')
for i in $url; do
pidof -q "$BROWSER" && "$BROWSER" "$i" \
|| setsid -f "$BROWSER" "$i"
done
else
url=$(printf '%s\n' "$urls" |tr ' ' '+')
pidof -q "$BROWSER" && "$BROWSER" "$default_se$url" \
|| setsid -f "$BROWSER" "$default_se$url"
fi