Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 398b3e797d
Fetching contributors…

Cannot retrieve contributors at this time

executable file 310 lines (256 sloc) 5.375 kb
#!/usr/bin/env bash
# version
VERSION="0.4.0"
# bookmarks dir
DIR=~/Dropbox
# thumbs cache
THUMBS=$DIR/bookmark-thumbs
# bookmarks file
BOOKMARKS=$DIR/bookmarks
# HTML file
HTML=/tmp/bm.html
#
# Output usage info
#
usage() {
cat <<EOF
Usage: bm [options] [cmd]
Commands:
# add a bookmark with the given url, description, and optional tags
$ bm add <url> [desc] [tag...]
# open the first bookmark matching <query>
$ bm open <query>
$ bm <query>
# search the bookmarks via full-text <query>
$ bm search <query>
# list bookmarks available
$ bm list
$ bm ls
$ bm
# view bookmark screenshots in your default browser
$ vm view design
$ vm view
# clear all bookmarks
$ bm clear
Options:
-V, --version output bm version
-h, --help output this help information
EOF
}
#
# Add a bookmark
#
# <url> [description] [tag ...]
#
save_bookmark() {
local url=$1
local desc=$2
local tags=${@:3}
echo
echo " Added bookmark"
echo
echo " url: $url"
echo " description: $desc"
echo " tags: $tags"
echo
echo "$url|$desc|$tags" >> $BOOKMARKS
}
#
# List all bookmarks
#
list_bookmarks() {
echo
cat $BOOKMARKS \
| awk '
BEGIN { FS = "|" }
{
printf " \033[36m%s\033[0m\n", $1
printf " \033[33m%s\033[0m\n", $2
printf " \033[90m%s\033[0m\n\n", $3
}' \
| sed 's/http:\/\///'
echo
}
#
# Search all bookmarks with <query>
#
search_bookmarks() {
echo
cat $BOOKMARKS \
| grep $1 \
| awk '
BEGIN { FS = "|" }
{
printf " \033[36m%s\033[0m\n", $1
printf " \033[33m%s\033[0m\n", $2
printf " \033[90m%s\033[0m\n\n", $3
}' \
| sed 's/http:\/\///'
echo
}
#
# Open first bookmark matching <query>
#
open_bookmark() {
cat $BOOKMARKS \
| grep $1 \
| cut -d '|' -f 1 \
| xargs open
}
#
# Stylesheet
#
style() {
cat <<EOF
<style>
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
padding: 50px 0 5px 50px;
background: url(http://subtlepatterns.com/patterns/black-Linen.png);
font: 12px "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.bm {
position: relative;
float: left;
margin: 15px;
padding: 1px;
opacity: 1;
border: 15px solid black;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-webkit-transition: -webkit-box-shadow 600ms;
-moz-transition: -webkit-box-shadow 600ms;
-webkit-box-shadow: 0 0 1px 0 #555, 0 0 10px rgba(0,0,0,.5);
-moz-box-shadow: 0 0 1px 0 #555, 0 0 10px rgba(0,0,0,.5);
overflow: hidden;
}
.bm:hover {
-webkit-box-shadow: 0 0 40px #1ab0ff
, 0 0 3px #06bdff
, 0 1px 1px #4ee2ff
, 0 1px 0 #fff;
-moz-box-shadow: 0 0 40px #1ab0ff
, 0 0 3px #06bdff
, 0 1px 1px #4ee2ff
, 0 1px 0 #fff;
}
.bm:hover img {
opacity: 1;
}
.bm img {
width: 200px;
height: 150px;
opacity: .5;
-webkit-transition: opacity 200ms;
-moz-transition: opacity 200ms;
}
.bm p {
margin: 0;
padding: 10px;
width: 100%;
background: rgba(0,0,0,.75);
position: absolute;
left: 0;
color: white;
letter-spacing: 1px;
bottom: -50px;
-webkit-font-smoothing: antialiased;
-webkit-transition: bottom 200ms ease-in;
}
.bm:hover p {
bottom: 0;
}
</style>
EOF
}
#
# List urls
#
urls() {
cat $BOOKMARKS \
| grep "$1" \
| cut -d '|' -f 1
}
#
# Generate bookmark screenshots
#
create_bookmark_screenshots() {
which webkit2png > /dev/null
if test $? -ne 0; then
echo
echo " You need webkit2png(1) installed for this feature:"
echo " $ brew install webkit2png"
echo
exit
fi
local urls=`urls`
# thumbs dir
mkdir -p $THUMBS
# fetch thumbs
for url in $urls; do
local path=$THUMBS/`echo $url | md5`.png
if ! test -f $path; then
webkit2png -C -o out.png $url
mv out.png-clipped.png $path
echo " ... added $path"
fi
done
rm -f out.png-{clipped,full,thumb}.png
}
#
# View bookmark screenshots.
#
view_bookmark_screenshots() {
create_bookmark_screenshots
echo "<title>Bookmarks</title>" > $HTML
style >> $HTML
(
while read line; do
# TODO: slow... refactor
local url=`echo "$line" | cut -d '|' -f 1`
local desc=`echo "$line" | cut -d '|' -f 2`
local tags=`echo "$line" | cut -d '|' -f 3`
local path=$THUMBS/`echo $url | md5`.png
echo "
<div class=bm>
<a href='$url'>
<img src='$path' />
</a>
<p>$desc</p>
</div>
" >> $HTML
done
) < $BOOKMARKS
open $HTML
}
#
# Remove all bookmarks
#
clear_bookmarks() {
rm $BOOKMARKS
rm -fr $THUMBS
}
# no args
if test $# -eq 0; then
list_bookmarks
exit
fi
# parse args
while test $# -ne 0; do
arg=$1; shift
case $arg in
-V|--version) echo $VERSION; exit ;;
-h|--help) usage; exit ;;
ls|list) list_bookmarks; exit ;;
search) search_bookmarks "$@"; exit ;;
open) open_bookmark "$@"; exit ;;
add) save_bookmark "$@"; exit ;;
view) view_bookmark_screenshots "$@"; exit ;;
clear) clear_bookmarks; exit ;;
*) open_bookmark $arg; exit ;;
esac
done
Jump to Line
Something went wrong with that request. Please try again.