Recently Written · git

sbm-suckless

sbm before the rewrite: bookmarks in a plain file, picked with dmenu. Suckless style.

git clone https://github.com/equwal/sbm-suckless

Log | Files | Refs


commit b0a9b7e0022a3038de42a18fa35d2ca221493be3
Spenser Truex <truex@equwal.com>
2023-07-30 17:05:27 -0300

Implement add and copy functions

Still need the edit and plumb to be hashed out.

 .gitignore |  2 ++
 Makefile   |  5 +++--
 TODO       |  9 ++++++---
 bm         | 49 ++++++++++++++++++++++++++++++++++++-------------
 bmks       | 52 +++++++++++++++++++++++++++++++++++++++++++++++-----
 usertags   | 11 +++++++++++
 6 files changed, 105 insertions(+), 23 deletions(-)
diff --git a/.gitignore b/.gitignore
index cdb722e..d2c33fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 tags.*
+bm
+bmks
diff --git a/Makefile b/Makefile
index f95883a..358edd7 100644
--- a/Makefile
+++ b/Makefile
@@ -7,9 +7,10 @@ dist:
 	@echo creating dist tarball
 	@mkdir -p sbm-${VERSION}-temp
 	@cp -R Makefile config.mk bm  sbm-${VERSION}-temp
-	@tar -cf sbm-${VERSION}.tar sbm-${VERSION}-temp
+	@mv sbm-${VERSION}-temp sbm-${VERSION}
+	@tar -cf sbm-${VERSION}.tar sbm-${VERSION}
 	@gzip sbm-${VERSION}.tar
-	@rm -rf sbm-${VERSION}-temp
+	@rm -rf sbm-${VERSION}
 
 install:
 	@echo installing scripts to ${DESTDIR}${PREFIX}/bin
diff --git a/TODO b/TODO
index 5d41c78..ba54bc6 100644
--- a/TODO
+++ b/TODO
@@ -1,8 +1,11 @@
-- Don't copy comments, just the bookmark.
+- [X] Don't copy comments, just the bookmark.
 - Be able to add bookmarks with a dmenu prompter that shows the other bookmarks.
+
+PREVENT DUPLICATES
 - prevent duplicates via http(s) difference
 - prevent duplicates via www subdomain
 - Allow any whitespace as a separator (except newline)
-- Be a simple CLI C program and use scripts for complex usage (like dmenu).
-- User-defined tags
+
+- [X] User-defined tags
 - make the use of xclip configurable (other programs exist)
+- figure out a dmenu websearch that utilizes bookmarks too
diff --git a/bm b/bm
index adb63b0..4b149e3 100755
--- a/bm
+++ b/bm
@@ -1,4 +1,12 @@
 #!/bin/sh
+
+# Don't forget to set $BOOKMARKS and $USERTAGS to files somewhere.
+# TODO:
+# - prevent duplicate URLs
+# - prevent duplicate tags during tag session
+# - prevent empty entries
+# - make the top tag a null tag so a user accidentally pressing ENTER twice doesn't close out the tag dialogue
+
 DMENULINES=15
 
 help () {
@@ -6,25 +14,40 @@ help () {
     echo "Flags:"
     printf "-h, --help\n-c, --copy\n-a, --add\n-e, --edit\n"
 }
+
 copy () {
     sort -t2 "$BOOKMARKS" | dmenu -i -l $DMENULINES -p "bookmark:" | cut -f 1 -d ' ' | xclip -i -selection clipboard
 }
-# add () {
-#
-# }
-# edit () {
-#
-# }
-# plumb () {
-# }
-#
+
+add () {
+    url="$(xclip -o | dmenu -p 'url: ')"
+    desc="$(dmenu -p 'description: ')"
+    tag=""
+    tags=""
+    while [ "$tag" != "done" ] ; do
+      [ ! -e "$tag" ] && tags="$tags $tag"
+      tag="$(echo "done | (choose when done)\n$(cat $USERTAGS)" | dmenu -i -l 15 -p 'tags: ' | sed 's/ *|.*$//')"
+    done
+    [ ! -e "$url" ] && printf "%s %s | %s\\n" "$url" "$desc" "$tags">>"$BOOKMARKS"
+}
+
+edit () {
+    echo "Not implemented. Edit \$BOOKMARKS yourself at $BOOKMARKS." && exit 1
+}
+
+plumb () {
+    echo "Not implemented" && exit 1
+}
+
 promptflag () {
-    action="$(printf 'copy\nadd\nedit' | dmenu -l 3 -p 'action:')"
-    [ "$action" = "copy" ] && copy
-    [ "$action" = "edit" ] && edit
-    [ "$action" = "add" ] && add
+
+    action="$(printf 'copy\nadd\nedit (not implemented)\nplumb (not implemented)' | dmenu -l 4 -p 'action:')"
+    [ "$action" = "copy" ]  && copy
+    [ "$action" = "edit" ]  && edit
+    [ "$action" = "add" ]   && add
     [ "$action" = "plumb" ] && plumb
 }
+
 [ "$1" = '-h' ] || [ "$1" = '--help' ] && help
 [ "$1" = '-c' ] || [ "$1" = '--copy' ] && copy
 [ "$1" = '-a' ] || [ "$1" = '--add' ]  && add
diff --git a/bmks b/bmks
index 2b521a2..a0c3cc4 100755
--- a/bmks
+++ b/bmks
@@ -11,24 +11,66 @@ show_usage() {
 	printf "bmks: unix bookmark management that sucks less
 
 usage:
+
+bmks [displayprog] command
+
+cli commands:
 bmks help
 	show this help message
 bmks add <url>
 	add a new bookmark
 bmks del
 	remove a bookmark
+bmks plumb
+	call plumber on a bookmark
 bmks ls
 	show all bookmarks
-bmks dmenu
-	manual switch for displaying bookmarks in dmenu
-bmks fzf
-	manual switch for displaying bookmarks in fzf
+
+display program commands:
+Example: bmks dmenu copy
+
+bmks [displayprog] copy
+	copy a bookmark
+bmks [displayprog] edit
+	edit a bookmark
+bmks [displayprog] add
+	add a bookmark
+bmks [displayprog] del
+	remove a bookmark
+bmks [displayprog] plumb
+	plumb (xdg) a bookmark
+bmks [displayprog] ls
+	show all bookmarks
+
+bmks dmenu, bmks fzf
+	Deprecated no-args commands. Displays bookmarks with dmenu or fzf.
+	
 
 Configuration is done by directly editing the script. Two launchers are available (dmenu and fzf). You can specify which one to use by adding to the PREFERED_LAUNCHER variable directly in the script. Both will display a menu that will allow you to choose a bookmark and open it in your default browser.
 
-If you would prefer to have your bookmarks stored in alternate location there are also variables that can be changed for that. The default is /home/user/.bmks/urls\n"
+If you would prefer to have your bookmarks stored in alternate location there are also variables that can be changed for that. The default is /home/user/.bmks/urls\n
+Call without an argument to be prompted with dmenu."
+
+#from my bm implementation -- use this
+#copy () {
+#    sort -t2 "$BOOKMARKS" | dmenu -i -l $DMENULINES -p "bookmark:" | cut -f 1 -d ' ' | xclip -i -selection clipboard
 }
 
+promptflag () {
+    action="$(printf 'copy\nadd\nedit' | dmenu -l 3 -p 'action:')"
+    [ "$action" = "copy" ] && copy
+    [ "$action" = "edit" ] && edit
+    [ "$action" = "add" ] && add
+    [ "$action" = "plumb" ] && plumb
+}
+[ "$1" = '-h' ] || [ "$1" = '--help' ] && help
+[ "$1" = '-c' ] || [ "$1" = '--copy' ] && copy
+[ "$1" = '-a' ] || [ "$1" = '--add' ]  && add
+[ "$1" = '-e' ] || [ "$1" = '--edit' ] && edit
+[ "$1" = '-e' ] || [ "$1" = '--plumb' ] && plumb
+[ -z "$1" ] && promptflag
+
+
 bmks_add() {
 	[ -z "$url" ] && printf "Error: url must be provided\n\n" && show_usage && exit 0
 	printf "Description: "
diff --git a/usertags b/usertags
new file mode 100644
index 0000000..b66d936
--- /dev/null
+++ b/usertags
@@ -0,0 +1,11 @@
+code  | code repos, docs
+users | personal sites
+sec   | information on privacy, security, or anonymity
+org   | organizations, businesses
+share | torrent trackers, information on downloading
+local | locally hosted files 
+tor   | onion sites, info about tor
+i2p   | eepsites, info about i2p
+lib   | books
+lang  | linguistics, dictionaries
+pol   | political content, opinion blogs