jarun / buku

:bookmark: Personal mini-web in text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New feature request : --force flag

leongm opened this issue · comments

Hi
buku is a great piece of job. I would like to use it for bookmark backup, syncing, im/export and manipulation (eg tag filtering). However, some buku operations (eg -d --ai etc) expect user interaction (typically y/n answer) and calling buku from a bash script to automate bookmark manipulation seems problematic. I wasnt able to find a suitable buku option that prevents this behavior. My attempts to bypass the buku prompt are based on the suggestions I found there https://askubuntu.com/questions/338857/automatically-enter-input-in-command-line and there
https://likegeeks.com/expect-command/. None of them was successful.
Is there any way to include some sort of --force flag or some other options that would allow buku to perform bookmark management without the user interaction or with default answer ?
I'm not a coder in any way and I am sorry I cannot develop myself such a feature to be ported to buku

commented

To some extent you can do that using the option --tacit.

Thank you for your answer. But still not the solution
buku --tacit -d prompts the user and buku --tacit --ai does not allow me to answer 'no' to chromium bookmark import and 'yes' to firefox bookmarks

commented

-d is completely destructive and the prompt was added based on an issue. It's much safer that way.

buku --tacit --ai is a one-time command. I don't see the issue.

about -d : yes it drops the database but it is no more destructive than usual commands such as rm. The latter defaults as an interactive command prompting the user to confirm the action ; but it has a --force flag allowing the user to bypass confirmation. buku -d could have the same behavior. Moreover, as buku imports bookmarks that are otherwise stored in various browser databases, bookmarks can still be recovered with buku --ai in case of unwanted buku -d --force

buku --tacit --ai is a one-time command. I don't see the issue

Assume that I want to import only firefox boorkmarks (not chromium). How can I do this with buku --tacit --ai?

Anyway, I managed to find a solution to my issue based on expect. I use the following script to first backup and then drop the current buku database and create and populate a new buku db with firefox bookmarks

I excecute the following script

#!/bin/sh

BINDIR=$HOME/bin
cp $HOME/.local/share/buku/bookmarks.db $HOME/.local/share/buku/bookmarks_$(date +%Y_%m_%d_%H_%M_%S).db
rm -f $HOME/.local/share/buku/bookmarks.db
exec $BINDIR/bukuexpect.sh

that calls bukuexpect.sh

#!/usr/bin/expect -f
##  bukuexpect.sh : automatic answers to buku --ai prompts

spawn buku -d
expect "Remove ALL bookmarks? (y/n):"
send "y\r"
spawn buku --ai
expect "Add parent folder names as tags? (y/n):"
send "y\r"
expect "Import bookmarks from google chrome? (y/n):"
send "n\r"
expect "Import bookmarks from chromium? (y/n):"
send "n\r"
expect "Import bookmarks from Firefox? (y/n):"
send "y\r"
expect eof

Thanks for your help. And again : buku is great :)

commented

This is a great solution! I will add it to the wiki.

commented

Added to the readme for other users. Thanks!