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


bmks (3588 bytes)

1 #! /bin/bash
2 
3 # set prefered launcher
4 PREFERED_LAUNCHER=dmenu
5 # set path where urls will be stored
6 URL_FILE_PATH=$HOME/.local/share/bookmarks
7 # name of file urls will be stored in
8 URL_FILE_NAME=urls
9 
10 show_usage() {
11 	printf "bmks: unix bookmark management that sucks less
12 
13 usage:
14 
15 bmks [displayprog] command
16 
17 cli commands:
18 bmks help
19 	show this help message
20 bmks add <url>
21 	add a new bookmark
22 bmks del
23 	remove a bookmark
24 bmks plumb
25 	call plumber on a bookmark
26 bmks ls
27 	show all bookmarks
28 
29 display program commands:
30 Example: bmks dmenu copy
31 
32 bmks [displayprog] copy
33 	copy a bookmark
34 bmks [displayprog] edit
35 	edit a bookmark
36 bmks [displayprog] add
37 	add a bookmark
38 bmks [displayprog] del
39 	remove a bookmark
40 bmks [displayprog] plumb
41 	plumb (xdg) a bookmark
42 bmks [displayprog] ls
43 	show all bookmarks
44 
45 bmks dmenu, bmks fzf
46 	Deprecated no-args commands. Displays bookmarks with dmenu or fzf.
47 	
48 
49 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.
50 
51 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
52 Call without an argument to be prompted with dmenu."
53 
54 #from my bm implementation -- use this
55 #copy () {
56 #    sort -t2 "$BOOKMARKS" | dmenu -i -l $DMENULINES -p "bookmark:" | cut -f 1 -d ' ' | xclip -i -selection clipboard
57 }
58 
59 promptflag () {
60     action="$(printf 'copy\nadd\nedit' | dmenu -l 3 -p 'action:')"
61     [ "$action" = "copy" ] && copy
62     [ "$action" = "edit" ] && edit
63     [ "$action" = "add" ] && add
64     [ "$action" = "plumb" ] && plumb
65 }
66 [ "$1" = '-h' ] || [ "$1" = '--help' ] && help
67 [ "$1" = '-c' ] || [ "$1" = '--copy' ] && copy
68 [ "$1" = '-a' ] || [ "$1" = '--add' ]  && add
69 [ "$1" = '-e' ] || [ "$1" = '--edit' ] && edit
70 [ "$1" = '-e' ] || [ "$1" = '--plumb' ] && plumb
71 [ -z "$1" ] && promptflag
72 
73 
74 bmks_add() {
75 	[ -z "$url" ] && printf "Error: url must be provided\n\n" && show_usage && exit 0
76 	printf "Description: "
77 	read description
78 	[ -z "$description" ] && echo "$url" >> $URL_FILE_PATH/$URL_FILE_NAME
79 	[ -n "$description" ] && echo "$description - $url" >> $URL_FILE_PATH/$URL_FILE_NAME
80 }
81 
82 bmks_ls() {
83 	bmks_check
84 	cat $URL_FILE_PATH/$URL_FILE_NAME | sort
85 }
86 
87 bmks_del() {
88 	bmks_check
89 	case $PREFERED_LAUNCHER in
90 		dmenu) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -l $(cat $URL_FILE_PATH/$URL_FILE_NAME | wc -l))/d" $URL_FILE_PATH/$URL_FILE_NAME ;;
91 		fzf) sed -i "/$(cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf)/d" $URL_FILE_PATH/$URL_FILE_NAME ;;
92 	esac
93 }
94 
95 bmks_display() {
96 	bmks_check
97 	case $PREFERED_LAUNCHER in
98 		dmenu) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | dmenu -l $(cat $URL_FILE_PATH/$URL_FILE_NAME | wc -l) | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;;
99 		fzf) cat $URL_FILE_PATH/$URL_FILE_NAME | sort | fzf | awk '{print $(NF)}' | xargs -I '{}' $BROWSER {} ;;
100 	esac
101 }
102 
103 bmks_check() {
104 	[ ! -s $URL_FILE_PATH/$URL_FILE_NAME ] && printf "Error: No bookmarks found to display. Try adding some!\n\n" && show_usage && exit 0
105 }
106 
107 [ ! -d $URL_FILE_PATH ] && mkdir $URL_FILE_PATH
108 [ ! -f $URL_FILE_PATH/$URL_FILE_NAME ] && touch $URL_FILE_PATH/$URL_FILE_NAME
109 
110 case "$1" in
111 	"help") show_usage ;;
112 	"add") url=$2; bmks_add ;;
113 	"del") bmks_del ;;
114 	"ls") bmks_ls ;;
115 	"dmenu") PREFERED_LAUNCHER=$1; bmks_display ;;
116 	"fzf") PREFERED_LAUNCHER=$1; bmks_display ;;
117 	*) bmks_display ;;
118 esac