Skip to content

Commit a779f40

Browse files
authored
Merge pull request #26 from TinyToolSH/dmenu_tbm
Added dmenu wrapper
2 parents 0dc262a + 42cd90f commit a779f40

File tree

5 files changed

+110
-3
lines changed

5 files changed

+110
-3
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added a `dmenu` wrapper called `dmenu_tbm` to manager your bookmarks;
13+
* If a `TBM_FILE` is empty or `/dev/stdout` the default file will be `$HOME/.tbookmarks`;
14+
* With `dmenu_tbm` you can:
15+
* create a `new` bookmark;
16+
* `open`, `delete` or copy (to clipboard) an existing one;
17+
* Added target to install `dmenu_tbm` script;
18+
1219
### Fixed
1320

1421
### Changed
1522

23+
* Updated `README.md` with `dmenu_tbm` reference;
24+
1625
### Removed
1726

1827
## [0.8.0]

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ all:
99
install:
1010
@echo "Installing ${name}..."
1111
install -m 555 ${name} $(DESTDIR)/$(prefix)/bin/
12+
install -m 555 dmenu_${name} $(DESTDIR)/$(prefix)/bin/
1213
@echo "done!"
1314

1415
clean:
@@ -19,6 +20,7 @@ distclean: clean
1920
uninstall:
2021
@echo "Uninstall ${name}"
2122
rm -f $(DESTDIR)/$(prefix)/bin/${name}
23+
rm -f $(DESTDIR)/$(prefix)/bin/dmenu_${name}
2224
@echo "done!"
2325

2426
.PHONY: all install clean distclean uninstall

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,16 @@ $ echo "export TBM_FILE=/path/to/tbm/storage/destination" >> $HOME/.zshrc
8282

8383
## dmenu
8484

85-
You can integrate `tbm` to `dmenu` if you want. We are using it as follows:
85+
You can integrate `tbm` to `dmenu` if you want. You can use it as follows:
8686

8787
```bash
8888
$ tbm -lt | dmenu -p "Bookmarks" | { read title; tbm -luf $title } | { read url; xdg-open $url }
8989
```
9090
91-
We recommend you to apply the [case-insensitive](https://tools.suckless.org/dmenu/patches/case-insensitive/) patch to your `dmenu`.
91+
Or, you can use our [dmenu_tbm](https://github.com/TinyToolSH/tbm/blob/main/dmenu_tbm) wrapper,
92+
which gives you some management options like `new` bookmark, `remove` an existing bookmark or `copy` to clipboard.
93+
94+
We'd recommend you to apply the [case-insensitive](https://tools.suckless.org/dmenu/patches/case-insensitive/) patch to your `dmenu`.
9295
9396
# Team
9497

dmenu_tbm

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/sh
2+
3+
#This file is part of the TinyTools distribution (https://github.com/Calebe94/TinyTools).
4+
#Copyright (C) 2021 TinyTools
5+
#
6+
#This program is free software: you can redistribute it and/or modify
7+
#it under the terms of the GNU General Public License as published by
8+
#the Free Software Foundation, either version 3 of the License, or
9+
#(at your option) any later version.
10+
#
11+
#This program is distributed in the hope that it will be useful,
12+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
#GNU General Public License for more details.
15+
#
16+
#You should have received a copy of the GNU General Public License
17+
#along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
20+
####################################################################################################
21+
# Variables used in the script.
22+
####################################################################################################
23+
DMENU_ARGS=$@
24+
TBM=tbm
25+
[ -z "$TBM_FILE" ] || [ "$TBM_FILE" = "/dev/stdout" ] && export TBM_FILE=$HOME/.tbookmarks
26+
27+
get_bookmark_url()
28+
{
29+
$TBM -l | grep "$1" | awk '{print $1}'
30+
}
31+
32+
get_bookmark_id()
33+
{
34+
$TBM -li | grep "$1" | awk '{print $1}' | rev | cut -c 2- | rev
35+
}
36+
37+
bookmark_action()
38+
{
39+
bookmark="$1"
40+
actions="[open]\n[copy]\n[delete]\n[back]\n[close]"
41+
selection=$(echo "$actions" | dmenu -p "$bookmark" $DMENU_ARGS)
42+
if [ ! -z "$selection" ]; then
43+
case "$selection" in
44+
"[open]")
45+
url=$(get_bookmark_url "$bookmark")
46+
[ -z "$url" ] && echo "No url given!" | dmenu -p "Error" $DMENU_ARGS || xdg-open "$url"
47+
;;
48+
"[copy]")
49+
url=$(get_bookmark_url "$bookmark")
50+
echo "$url" | xclip -selection clipboard
51+
;;
52+
"[delete]")
53+
choice=$(echo "no\nyes" | dmenu -p "Are you sure?" $DMENU_ARGS)
54+
if [ "$choice" = "yes" ]; then
55+
id=$(get_bookmark_id "$bookmark")
56+
[ -z "$id" ] && echo "No id given!" | dmenu -p "Error" $DMENU_ARGS || tbm -d "$id"
57+
else
58+
bookmark_action "$bookmark"
59+
fi
60+
;;
61+
"[back]") show_bookmarks ;;
62+
*) exit 0 ;;
63+
esac
64+
fi
65+
}
66+
67+
list_bookmarks_titles()
68+
{
69+
$TBM -lt
70+
}
71+
72+
show_bookmarks()
73+
{
74+
actions="[new]\n[close]\n"
75+
bookmarks="$actions$(list_bookmarks_titles)"
76+
selection=$(echo "$bookmarks" | dmenu -p "Bookmarks" $DMENU_ARGS)
77+
if [ ! -z "$selection" ]; then
78+
case "$selection" in
79+
"[new]")
80+
status=$($TBM "$(xclip -o -selection clipboard)")
81+
[ -z "$status" ] && echo "No url on clipboard!" | dmenu -p "Error" $DMENU_ARGS || echo "$status"
82+
;;
83+
"[close]") exit 0 ;;
84+
*) bookmark_action "$selection" ;;
85+
esac
86+
fi
87+
}
88+
89+
###################################################################################################
90+
############################################## MAIN ###############################################
91+
###################################################################################################
92+
93+
show_bookmarks

tbm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ list_by_title()
6363
if [ $id -eq 1 ]; then
6464
awk '{out=$1""; for(i=3; i<=NF; i++){out=out" "$i}; print out}'
6565
else
66-
awk '{$1=""; print $0}'
66+
awk '{$1=""; print $0}' | cut -c 2-
6767
fi
6868
}
6969

0 commit comments

Comments
 (0)