Initial import of bookmarks.sh - bookmarks.sh - Simple bookmark manager
 (HTM) hg clone https://bitbucket.org/iamleot/bookmarks.sh
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) changeset 644e21164c4fc1b3c1cb66846701ac9bd08214ff
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Mon,  1 Jan 2018 01:46:09 
       
       Initial import of bookmarks.sh
       
       Diffstat:
        bookmarks.sh |  155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        1 files changed, 155 insertions(+), 0 deletions(-)
       ---
       diff -r 000000000000 -r 644e21164c4f bookmarks.sh
       --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
       +++ b/bookmarks.sh      Mon Jan 01 01:46:09 2018 +0100
       @@ -0,0 +1,155 @@
       +#!/bin/sh
       +
       +#
       +# Copyright (c) 2017 Leonardo Taccari
       +# All rights reserved.
       +# 
       +# Redistribution and use in source and binary forms, with or without
       +# modification, are permitted provided that the following conditions
       +# are met:
       +# 
       +# 1. Redistributions of source code must retain the above copyright
       +#    notice, this list of conditions and the following disclaimer.
       +# 2. Redistributions in binary form must reproduce the above copyright
       +#    notice, this list of conditions and the following disclaimer in the
       +#    documentation and/or other materials provided with the distribution.
       +# 
       +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
       +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
       +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
       +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
       +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
       +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
       +# POSSIBILITY OF SUCH DAMAGE.
       +#
       +
       +
       +: ${BOOKMARKS:="${HOME}/.bookmarks"}
       +
       +_bookmarks=${BOOKMARKS}        # bookmark file used
       +
       +
       +#
       +# Append all arguments to the bookmark file.
       +# At least two arguments are needed.
       +#
       +add()
       +{
       +
       +       if [ $# -lt 2 ]; then
       +               return
       +       fi
       +
       +       local id="$1"
       +       local url="$2"
       +       local tags="$3"
       +       local comment="$4"
       +
       +       printf "$id\t$url\t$tags\t$comment\n" >> $_bookmarks
       +}
       +
       +#
       +# Delete all the bookmarks which matches the id of the argument.
       +#
       +delete()
       +{
       +
       +       if [ $# -ne 1 ]; then
       +               return
       +       fi
       +
       +       local id="$1"
       +
       +       sed -i -e "/^${id}      /d" $_bookmarks
       +}
       +
       +#
       +# List all bookmarks.
       +#
       +list()
       +{
       +
       +       cat $_bookmarks
       +}
       +
       +#
       +# Search for a given field in the bookmarks and print all the matching
       +# bookmark entries.
       +#
       +search()
       +{
       +
       +       if [ $# -ne 1 ]; then
       +               return
       +       fi
       +
       +       local field="$1"
       +
       +       case ${field} in
       +       @*)
       +               # tag
       +               awk -vtag="${field}" -F '\t' 'index($3, tag) { print }' $_bookmarks
       +               ;;
       +       *://*)
       +               # url
       +               awk -vurl="${field}" -F '\t' '$2 == url { print }' $_bookmarks
       +               ;;
       +       *)
       +               # id
       +               awk -vid="${field}" -F '\t' '$1 == id { print }' $_bookmarks
       +               ;;
       +       esac
       +}
       +
       +#
       +# Print usage information and exit.
       +#
       +usage()
       +{
       +       local progname=`basename "$0"`
       +
       +       echo "usage: $progname command ..."
       +       echo "    $progname add id url [tags [comment]]"
       +       echo "    $progname delete id"
       +       echo "    $progname list"
       +       echo "    $progname search id|url|tag"
       +
       +       exit 1
       +}
       +
       +main()
       +{
       +
       +       if [ $# -lt 1 ]; then
       +               usage
       +       fi
       +
       +       local action="$1"
       +       shift
       +
       +       case $action in
       +       add)
       +               add "$@"
       +               ;;
       +       delete)
       +               delete "$@"
       +               ;;
       +       list)
       +               list "$@"
       +               ;;
       +       search)
       +               search "$@"
       +               ;;
       +       *)
       +               usage
       +               ;;
       +       esac
       +
       +       exit 0
       +}
       +
       +main "$@"