Skip to content

Commit 54fcdd7

Browse files
authored
Merge pull request #23 from GandaG/display-title
Add multiple display types
2 parents fe3ecf9 + eb43d96 commit 54fcdd7

File tree

2 files changed

+108
-7
lines changed

2 files changed

+108
-7
lines changed

Diff for: buku_run

+104-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ _rofi () {
44
rofi -dmenu -i -no-levenshtein-sort -width 1000 "$@"
55
}
66

7+
# display settings
8+
display_type=1
9+
max_str_width=80
10+
711
# keybindings
812
switch_view="Alt+Tab"
913
new_bookmark="Alt+n"
@@ -43,7 +47,7 @@ main () {
4347
HELP="Welcome to Buku. Use <span color='${help_color}'>${new_bookmark}</span> to add a new Bookmark
4448
Use <span color='${help_color}'>${switch_view}</span> to switch View. <span color='${help_color}'>${actions}</span> for actions"
4549
if [[ $mode == "bookmarks" ]]; then
46-
content=$(buku -p -f 2 | awk 'NF == 2 { $0 = $0 "NOTAG" }; { $2 = substr($2,0,80); print $1"\t"$2"\t"$3,$4,$5 }' | column -t -s $'\t')
50+
content=$(parseBuku)
4751
menu=$(echo "${content}" | _rofi -p '> ' -filter "${filter}" -mesg "${HELP}" -kb-custom-1 "${new_bookmark}" -kb-custom-2 "${switch_view}" -kb-custom-3 "${actions}" -kb-custom-4 "${edit}" -kb-custom-5 "${delete}")
4852
elif [[ $mode == "tags" ]]; then
4953
menu=$(buku --np --st | awk '{$NF=""; print $0}' | cut -d ' ' -f2- | _rofi -p '> ' -mesg "${HELP}" -kb-custom-1 "${new_bookmark}" -kb-custom-2 "${switch_view}" -kb-custom-3 "${actions}" -kb-custom-4 "${edit}" -kb-custom-5 "${delete}")
@@ -69,7 +73,7 @@ Use <span color='${help_color}'>${switch_view}</span> to switch View. <span colo
6973
fi
7074
elif [[ $val -eq 0 ]]; then
7175
if [[ $mode == "bookmarks" ]]; then
72-
id=$(echo "${menu%% *}")
76+
id=$(getId "$content" "$menu")
7377
for bm in ${id}; do
7478
buku -o "${bm}"
7579
done
@@ -136,7 +140,7 @@ optionsMenu () {
136140
}
137141

138142
deleteMenu () {
139-
id=$(echo "${menu}" | awk '{ print $1 }')
143+
id=$(getId "$content" "$menu")
140144
delask=$(echo -e "1. Yes\n2. No" | _rofi -p '> ' -mesg "Really delete bookmark?")
141145
val=$?
142146
if [[ $val -eq 1 ]]; then
@@ -152,10 +156,11 @@ deleteMenu () {
152156
}
153157

154158
editMenu () {
155-
bookmark=$(echo "${menu}" | awk '{ print $2 }')
156-
id=$(echo "${menu}" | awk '{ print $1 }')
157-
tags=$(echo "${menu}" | awk '{ print substr($0, index($0,$3)) }' | sed 's/NOTAG//g')
158-
content=$(echo -e "1. url: $bookmark\n2. tags: $tags")
159+
id=$(getId "$content" "$menu")
160+
title="$(getTitleFromId $id)"
161+
bookmark="$(getUrlFromId $id)"
162+
tags="$(getTagsFromId $id)"
163+
content=$(echo -e "1. title: $title\n2. url: $bookmark\n3. tags: $tags")
159164
editmenu=$(echo -e "< Return\n---\n${content}" | _rofi -p '> ')
160165
val=$?
161166
if [[ $val -eq 1 ]]; then
@@ -169,6 +174,8 @@ editMenu () {
169174
tags="${tags}" editTags
170175
elif [[ $editmenu =~ url:* ]]; then
171176
editBookmark
177+
elif [[ $editmenu =~ title:* ]]; then
178+
editTitle
172179
fi
173180
fi
174181
}
@@ -200,6 +207,17 @@ editBookmark () {
200207
mode=bookmarks main
201208
}
202209

210+
editTitle () {
211+
titlemenu=$(echo "" | _rofi -p "> " -filter "${title}" -mesg "Edit Title and hit Enter")
212+
val=$?
213+
if [[ $val -eq 1 ]]; then
214+
exit
215+
elif [[ $val -eq 0 ]]; then
216+
buku -u "${id}" --title "${titlemenu}"
217+
fi
218+
mode=bookmarks main
219+
}
220+
203221
addMark () {
204222
inserturl=$(echo -e "$(xclip -o)" | _rofi -p '> ' -mesg "Use URL below or type manually")
205223
val=$?
@@ -232,4 +250,83 @@ addTags () {
232250
fi
233251
fi
234252
}
253+
254+
parseBuku () {
255+
echo "$(buku --nc -p | gawk -v max="$max_str_width" -v type="$display_type" '
256+
BEGIN {
257+
RS=""
258+
FS="\n"
259+
}
260+
{
261+
if ($3 == "")
262+
$3 = " # NOTAG"
263+
id = gensub(/([0-9]+)\.(.*)/, "\\1", "g", $1)
264+
url = substr(gensub(/\s+> (.*)/, "\\1", "g", $2),0,max)
265+
tags = gensub(/\s+# (.*)/, "\\1", "g", $3)
266+
title = substr(gensub(/[0-9]+\.\s*(.*)/, "\\1", "g", $1),0,max)
267+
268+
if (type == 1)
269+
print id "\t" url "\t" tags
270+
else
271+
print id "\t" title "\t" tags
272+
if (type == 3)
273+
print " \t" url "\t "
274+
print ""
275+
}
276+
' | column -t -s $'\t')"
277+
}
278+
279+
getId () {
280+
id=$(echo "${2%% *}")
281+
if [ -z "$id" ]; then
282+
prev=""
283+
IFS=$'\n'
284+
for line in $1; do
285+
if [ "$2" = "$line" ]; then
286+
id=$(echo "${prev%% *}")
287+
break
288+
else
289+
prev="$line"
290+
fi
291+
done
292+
fi
293+
echo $id
294+
}
295+
296+
getTitleFromId () {
297+
echo "$(buku --nc -p $1 | gawk '
298+
BEGIN {
299+
RS=""
300+
FS="\n"
301+
}
302+
{
303+
print gensub(/[0-9]+\.\s*(.*)/, "\\1", "g", $1)
304+
}
305+
')"
306+
}
307+
308+
getUrlFromId () {
309+
echo "$(buku --nc -p $1 | gawk '
310+
BEGIN {
311+
RS=""
312+
FS="\n"
313+
}
314+
{
315+
print gensub(/\s+> (.*)/, "\\1", "g", $2)
316+
}
317+
')"
318+
}
319+
320+
getTagsFromId () {
321+
echo "$(buku --nc -p $1 | gawk '
322+
BEGIN {
323+
RS=""
324+
FS="\n"
325+
}
326+
{
327+
print gensub(/\s+# (.*)/, "\\1", "g", $3)
328+
}
329+
')"
330+
}
331+
235332
mode=bookmarks main

Diff for: config.buku

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ _rofi () {
44
rofi -dmenu -i -no-levenshtein-sort -width 1000 "$@"
55
}
66

7+
# display settings
8+
display_type=1
9+
max_str_width=80
10+
711
# keybindings
812
switch_view="Alt+Tab"
913
new_bookmark="Alt+n"

0 commit comments

Comments
 (0)