init
[dotfiles.git] / Scripts / pbm
1 #!/bin/sh
2 # Pinosaur's BookMarking or pbm
3 #
4 # The bookmark file should have one url on each line
5 # Empty lines and lines with a # symbol will be ignored
6 #
7 # You can also add an alias for each url 
8 # Just add the alias as a second column on the same line
9 #
10 # example:
11 # https://suckless.org/ ~suckless
12 #
13 # Requires dmenu with the 'reject no match' patch,
14 # available at https://tools.suckless.org/dmenu/patches/reject-no-match/dmenu-rejectnomatch-4.7.diff
15 #
16 # this script is horrible, ill try to improve it once im better at shell scripting
17
18 BOOKMARKS_FILE="$HOME/Data/bookmarks"
19
20 open() {
21     # Some error checking
22     [ -z $BROWSER ] &&\
23         echo "No browser set, try setting your $BROWSER environmental variable" &&\
24         exit 1
25
26     selection="$(cat "$BOOKMARKS_FILE" | egrep -v '^$' | grep -v '#' \
27         | awk '{ print $2 }'\
28         | dmenu -r \
29         )"
30
31     # Make sure that user actually selects a url
32     [ -z "$selection" ] &&\
33         echo "No url selected" && exit 1
34
35     url="$(cat "$BOOKMARKS_FILE" | egrep "\s$selection" | awk '{ print $1 }')"
36     $BROWSER "${url}" 
37 }
38
39 add() {
40     echo "Not implemented yet lolz"
41 }
42
43 [ "$1" = "-o" ] &&\
44     open &&\
45     exit 0
46 [ "$1" = "-a" ] &&\
47     add &&\
48     exit 0
49 echo "Invalid flags" && exit 1
50
51