commit a5412a6ee312c289b8bf501a96c239fe0e9a98dc
Author: Tomas Nemec <nemi@skaut.cz>
Date: Mon, 9 Aug 2021 23:14:16 +0200
init
Diffstat:
A | LICENSE | | | 21 | +++++++++++++++++++++ |
A | Makefile | | | 19 | +++++++++++++++++++ |
A | README | | | 26 | ++++++++++++++++++++++++++ |
A | bmadd | | | 22 | ++++++++++++++++++++++ |
A | bmls | | | 9 | +++++++++ |
A | bmmenu | | | 45 | +++++++++++++++++++++++++++++++++++++++++++++ |
A | bmrm | | | 27 | +++++++++++++++++++++++++++ |
7 files changed, 169 insertions(+), 0 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) [year] [fullname]
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/Makefile b/Makefile
@@ -0,0 +1,19 @@
+PREFIX = /usr/local
+BINDIR = $(PREFIX)/bin
+
+all:
+ @echo "Nothing to do, try \"make install\" instead."
+
+install:
+ @install -v -d "$(BINDIR)/" && install -m 0755 -v "./bmadd" "$(BINDIR)/bmadd"
+ @install -v -d "$(BINDIR)/" && install -m 0755 -v "./bmls" "$(BINDIR)/bmls"
+ @install -v -d "$(BINDIR)/" && install -m 0755 -v "./bmrm" "$(BINDIR)/bmrm"
+ @install -v -d "$(BINDIR)/" && install -m 0755 -v "./bmmenu" "$(BINDIR)/bmmenu"
+
+uninstall: trun.lua
+ @rm -vrf "$(BINDIR)/bmadd"
+ @rm -vrf "$(BINDIR)/bmls"
+ @rm -vrf "$(BINDIR)/bmrm"
+ @rm -vrf "$(BINDIR)/bmmenu"
+
+.PHONY: all install uninstall
diff --git a/README b/README
@@ -0,0 +1,26 @@
+Bookmark system - v1.0.0 ( 09.08.2021 )
+
+Depends on $BOOKMARK environment variable. It needs to contain path to file.
+Bookmarks are written in markdown like format:
+
+ [name](url)tag1,tag2
+
+available commands:
+
+* bmadd <name> <url> [<tags>]
+ Add bookmark.
+
+* bmls
+ List out all bookmarks
+
+* bmrm
+ Removes bookmarks passed to stdin. Preferred usage:
+ bmls | grep "SEARCHSTRING" | bmrm
+
+* bmmenu [--new-window]
+ Run dmenu and pass selected bookmark to $BROWSER.
+
+
+License in /LICENSE
+Feel free to contact me via mail:
+<nemi@skaut.cz>
diff --git a/bmadd b/bmadd
@@ -0,0 +1,22 @@
+#!/usr/bin/env zsh
+# Add bookmark
+
+usage="usage: <name> <url> [<tags>]"
+
+if [[ ! -f ${BOOKMARK} ]]; then
+ echo "BOOKMARK env is not set or not a file" >&2
+ exit 1
+fi
+
+function add() {
+ name=$1
+ url=$2
+ tags=$3
+ if [[ -z "$name" || -z "$url" ]]; then
+ echo $usage >&2
+ exit 1
+ fi
+ printf "[%s](%s)%s\n" $name $url $tags >&1 >> $BOOKMARK
+}
+
+add "$@"
diff --git a/bmls b/bmls
@@ -0,0 +1,9 @@
+#!/usr/bin/env zsh
+# List bookmarks
+
+if [[ ! -f ${BOOKMARK} ]]; then
+ echo "BOOKMARK env is not set or not a file" >&2
+ exit 1
+fi
+
+cat $BOOKMARK
diff --git a/bmmenu b/bmmenu
@@ -0,0 +1,45 @@
+#!/usr/bin/env zsh
+
+if [[ ! -f ${BOOKMARK} ]]; then
+ echo "BOOKMARK env is not set or not a file" >&2
+ exit 1
+fi
+
+key="templates"
+newwin=""
+while test $# -gt 0; do
+ case "$1" in
+ --new-window)
+ newwin="--new-window"
+ shift
+ ;;
+ *)
+ break
+ ;;
+ esac
+done
+
+[[ $DEBUG == 1 ]] && echo "newwin=$newwin"
+
+function open() {
+ bmark=$1
+ [[ -n $bmark ]] || return
+
+ title="$(awk 'BEGIN{FS=" "} {print $1}' <<< $bmark)"
+ url="$(awk 'BEGIN{FS=" "} {print $2}' <<< $bmark)"
+ tags="$(awk 'BEGIN{FS=" "} {print $3}' <<< $bmark)"
+
+ if [[ "$tags" =~ "$key" ]]; then
+ add=$(echo "" | dmenu -p $url)
+ $BROWSER $newwin $url$add
+ else
+ $BROWSER $newwin $url
+ fi
+}
+
+sed -E 's/\[(.*)\]\((.*)\) ?(.*)?/\1 \2 \3/' $BOOKMARK | dmenu -i -p bmark: -l 8 |
+while IFS= read -r line
+do
+ [[ $DEBUG == 1 ]] && echo "line=$line"
+ open "$line"
+done
diff --git a/bmrm b/bmrm
@@ -0,0 +1,27 @@
+#!/usr/bin/env zsh
+# Remove bookmarks
+#
+# Usage: bmls | grep "STRING" | bmrm
+
+if [[ ! -f ${BOOKMARK} ]]; then
+ echo "BOOKMARK env is not set or not a file" >&2
+ exit 1
+fi
+
+while read line; do
+ founds=$(grep -iFn "$line" < $BOOKMARK)
+ if [[ -z $founds ]];then
+ echo "Nothing removed" >&2
+ exit 1
+ fi
+ count=$(wc -l <<< "$founds")
+ if [[ $count -gt 1 ]]; then
+ echo "Found more than single line for '${line}':\n" >&2
+ echo "${founds}"
+ exit 1
+ fi
+ if [[ $count -eq 1 ]]; then
+ num=("${(@s/:/)founds}")
+ sed -i "${num[1]}d" $BOOKMARK
+ fi
+done