Skip to content

Commit c9053d4

Browse files
committed
[scripts] ,bm: use tab-separated picker format for cleaner selection
Adds picker_format that outputs url<tab>title+tags so fzf can display titles while returning the raw URL via cut -f1, avoiding regex extraction.
1 parent 542716c commit c9053d4

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

  • scripts/.local/bin/random

scripts/.local/bin/random/,bm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ render() {
4141
sed 's/#\([^ ]*\)/\x1b[36m#\1\x1b[0m/g'
4242
}
4343

44+
# format for picker: url<tab>Title #tag1 #tag2 (with colored tags)
45+
picker_format() {
46+
sed 's/^- \[\([^]]*\)\](\([^)]*\))\(.*\)/\2\t\1\3/' |
47+
sed 's/#\([^ ]*\)/\x1b[36m#\1\x1b[0m/g'
48+
}
49+
4450
case "$OPERATION" in
4551
help)
4652
echo "Usage: ,bm [command] [url]"
@@ -111,31 +117,31 @@ edit)
111117
;;
112118
show | pick)
113119
check_bookmarks
114-
result="$(cat "$BM_FILE" | ,picker -1 -i -m -e ${SEARCH_TERM:+"$SEARCH_TERM"} || true)"
120+
result="$(cat "$BM_FILE" | picker_format | ,picker -1 -i -m -e --ansi -d $'\t' --with-nth 2.. ${SEARCH_TERM:+"$SEARCH_TERM"} || true)"
115121
if [ -z "$result" ]; then
116122
echo "No links found" >&2
117123
exit 1
118124
fi
119-
echo "$result" | extract_url
125+
echo "$result" | cut -f1
120126
;;
121127
open)
122128
check_bookmarks
123-
result="$(cat "$BM_FILE" | ,picker -1 -i -m -e ${SEARCH_TERM:+"$SEARCH_TERM"} || true)"
129+
result="$(cat "$BM_FILE" | picker_format | ,picker -1 -i -m -e --ansi -d $'\t' --with-nth 2.. ${SEARCH_TERM:+"$SEARCH_TERM"} || true)"
124130
if [ -z "$result" ]; then
125131
echo "No links found" >&2
126132
exit 1
127133
fi
128-
echo "$result" | extract_url |
134+
echo "$result" | cut -f1 |
129135
while IFS= read -r url; do
130136
open "$url"
131137
done
132138
;;
133139
remove)
134140
check_bookmarks
135-
selected="$(cat "$BM_FILE" | ,picker -i -m -e ${SEARCH_TERM:+"$SEARCH_TERM"} || true)"
141+
selected="$(cat "$BM_FILE" | picker_format | ,picker -i -m -e --ansi -d $'\t' --with-nth 2.. ${SEARCH_TERM:+"$SEARCH_TERM"} || true)"
136142
if [ -n "$selected" ]; then
137-
echo "$selected" | while IFS= read -r line; do
138-
grep -vF "$line" "$BM_FILE" >"$BM_FILE.tmp"
143+
echo "$selected" | cut -f1 | while IFS= read -r url; do
144+
grep -vF "($url)" "$BM_FILE" >"$BM_FILE.tmp"
139145
mv "$BM_FILE.tmp" "$BM_FILE"
140146
done
141147
fi

0 commit comments

Comments
 (0)