-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmarks-uri-handler
executable file
·35 lines (29 loc) · 1.15 KB
/
bookmarks-uri-handler
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
#! /usr/bin/env bash
if [ ! -z "$1" ]; then
# extract the protocol
protocol="$(echo $1 | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol
payload=$(echo $1 | sed -e s,$protocol,,g)
query=$(echo "$payload" | sed 's,^.*?,,')
# extract the GET params from the query string
# get params are in the form of key=value
# concatenated with &
declare -A params
for param in $(echo "$query" | tr '&' '\n'); do
key=$(echo "$param" | cut -f1 -d=)
value=$(echo "$param" | cut -f2 -d=)
params["$key"]="$value"
done
# extract title, uri, category and tags from the params
title="${params['title']}"
uri="${params['uri']}"
category="${params['category']}"
tags="${params['tags']}"
# check if the tags are enclosed in square brackets
if [[ $tags == \[*\] ]]; then
# remove the square brackets from the tags
tags="${tags:1:${#tags}-2}"
fi
BOOKMARKS_INSTALL_DIR=/usr/local/bash-bookmarks
gnome-terminal -- /bin/bash -c "$BOOKMARKS_INSTALL_DIR/bookmarks add --title \"$title\" --uri \"$uri\" --category \"$category\" --tags \"$tags\"; exec /bin/bash"
fi