Edit last record in EDITOR (option -w) if id=-1.

This is a convenience feature. If the user is using a keyboard shortcut to add
a selected link as bookmark from the DE, he may want to edit it shortly. The -1
index enables him to open the last bookmark added without using option `-p -1`.
This commit is contained in:
Arun Prakash Jana 2017-10-09 01:21:13 +05:30
parent df5bdc1921
commit f72f8af3d8
No known key found for this signature in database
GPG Key ID: A75979F35C080412
3 changed files with 13 additions and 3 deletions

View File

@ -160,7 +160,8 @@ GENERAL OPTIONS:
- otherwise refresh all titles - otherwise refresh all titles
-w, --write [editor|index] -w, --write [editor|index]
open editor to edit a fresh bookmark open editor to edit a fresh bookmark
to update by index, EDITOR must be set edit last bookmark, if index=-1
to specify index, EDITOR must be set
-d, --delete [...] remove bookmarks from DB -d, --delete [...] remove bookmarks from DB
accepts indices or a single range accepts indices or a single range
if no arguments: if no arguments:

2
buku.1
View File

@ -105,7 +105,7 @@ Edit a bookmark in
.I editor .I editor
before adding it. To edit and update an existing bookmark, the before adding it. To edit and update an existing bookmark, the
.I index .I index
should be passed. However, in this case the environment variable EDITOR must be set. should be passed. However, in this case the environment variable EDITOR must be set. The last record is opened in EDITOR if index=-1.
.TP .TP
.BI \-d " " \--delete " [...]" .BI \-d " " \--delete " [...]"
Delete bookmarks. Accepts space-separated list of indices (e.g. 5 6 23 4 110 45) or a single hyphenated range (e.g. 100-200). Note that range and list don't work together. Deletes search results when combined with search options, if no arguments. Delete bookmarks. Accepts space-separated list of indices (e.g. 5 6 23 4 110 45) or a single hyphenated range (e.g. 100-200). Note that range and list don't work together. Deletes search results when combined with search options, if no arguments.

11
buku.py
View File

@ -1160,6 +1160,7 @@ class BukuDb:
---------- ----------
index : int index : int
DB index of the record. DB index of the record.
Last record, if index is -1.
immutable : int, optional immutable : int, optional
Diable title fetch from web if 1. Default is -1. Diable title fetch from web if 1. Default is -1.
@ -1174,6 +1175,13 @@ class BukuDb:
logerr('EDITOR must be set to use index with -w') logerr('EDITOR must be set to use index with -w')
return False return False
if (index == -1):
# Edit the last records
index = self.get_max_id()
if index == -1:
logerr('Empty database')
return False
rec = self.get_rec_by_id(index) rec = self.get_rec_by_id(index)
if not rec: if not rec:
logerr('No matching index %d', index) logerr('No matching index %d', index)
@ -3846,7 +3854,8 @@ POSITIONAL ARGUMENTS:
- otherwise refresh all titles - otherwise refresh all titles
-w, --write [editor|index] -w, --write [editor|index]
open editor to edit a fresh bookmark open editor to edit a fresh bookmark
to update by index, EDITOR must be set edit last bookmark, if index=-1
to specify index, EDITOR must be set
-d, --delete [...] remove bookmarks from DB -d, --delete [...] remove bookmarks from DB
accepts indices or a single range accepts indices or a single range
if no arguments: if no arguments: