#!/bin/ksh # # Copyright (c) 2020 Uwe Werler # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # # # This script opens all bookmarks matching tag(s) in vimb browser. This # simulates a session-like behaviour I used especially with pinned tabs in # Iridium. It can start vimb browser also in tabbed. Can be invoked via a key # binding in cwm. set -A _ARGS -- "${@}" _bookmark="${HOME}/.config/vimb/bookmark" usage(){ print \ " usage: $0 [ -f file ] [ -t ] [ tag ... ] -f: use non default bookmark file -t: start vimb in tabbed tag: case insensitive tag to match in bookmarks to open in vimb " exit 1 } _startvimb() { type vimb >/dev/null || print "Can't find vimb." if [[ -n ${_tabbed} ]]; then type tabbed >/dev/null || print "Can't find tabbed." [[ -z ${_winid} ]] && _winid=$(tabbed -n vimb -c -d 2>/dev/null) vimb --embed ${_winid} ${1} & else vimb ${1} & fi } _readbookmarks() { typeset -l local _tag typeset -l local _tags local URL { while read _url _tags; do for _tag in $@; do for _t in ${_tags}; do if [[ ${_t} == ${_tag} ]]; then _tagmatch=1 # don't start vimb multiple times when more than one tag matches [[ ${URL} != ${_url} ]] && _startvimb ${_url} URL=${_url} fi done done done } <${_bookmark} [[ -z ${_tagmatch} ]] && print "No matching tags found." } while getopts "f:t" _opt; do case "${_opt}" in f) unset _ARGS[0] unset _ARGS[1] _bookmark=${OPTARG} set -A _ARGS -- ${_ARGS[@]} ;; t) unset _ARGS[0] set -A _ARGS -- ${_ARGS[@]} _tabbed=1 ;; *) usage ;; esac done [[ -z ${_ARGS[*]} ]] && print "Missing tag argument." && usage shift $((OPTIND-1)) [ $# -gt 0 ] || usage if [[ -r ${_bookmark} ]]; then _readbookmarks ${_ARGS[@]} else print "Cant't read bookmark file." usage fi #vim: set ai:ts=2:et:sw=2