wallr: Add direct article selection option
Added `-a` option which can be supplied with an article id that wallr will open directly. Article ids can take the absolute form of e.g. `-a 1048` opening article with id 1048. They can also take the relative form of e.g. `-a +2` which will open the third-to-last entry in wallabag, i.e. count backwards from newest. That means you can use `-a +0` for example to always directly open the newest entry.
This commit is contained in:
parent
a85519e1cb
commit
3763c7e581
1 changed files with 44 additions and 11 deletions
|
@ -10,22 +10,31 @@ WALLR_MARKREAD=true
|
||||||
|
|
||||||
# get listing of all (read/unread/starred/all) wallabag articles
|
# get listing of all (read/unread/starred/all) wallabag articles
|
||||||
get_articles() {
|
get_articles() {
|
||||||
|
WALLR_article_listing=""
|
||||||
if [ "$WALLR_FILTER" = "all" ]; then
|
if [ "$WALLR_FILTER" = "all" ]; then
|
||||||
wallabag list
|
WALLR_article_listing=$(wallabag list)
|
||||||
elif [ "$WALLR_FILTER" = "starred" ]; then
|
elif [ "$WALLR_FILTER" = "starred" ]; then
|
||||||
wallabag list -s
|
WALLR_article_listing=$(wallabag list -s)
|
||||||
elif [ "$WALLR_FILTER" = "unread" ]; then
|
elif [ "$WALLR_FILTER" = "unread" ]; then
|
||||||
wallabag list -n
|
WALLR_article_listing=$(wallabag list -n)
|
||||||
|
elif [ "$WALLR_FILTER" = "last" ]; then
|
||||||
|
WALLR_article_listing=$(wallabag list -q 1)
|
||||||
else
|
else
|
||||||
wallabag list -r
|
WALLR_article_listing=$(wallabag list -r)
|
||||||
fi
|
fi
|
||||||
|
echo "$WALLR_article_listing" | head -n-1 | tail -n+2
|
||||||
}
|
}
|
||||||
|
|
||||||
# return the ID of article from listing version
|
# list articles and choose with fzf
|
||||||
|
fuzzy_select() {
|
||||||
|
[ -z "$1" ] && exit 1
|
||||||
|
echo "$1" | fzf "${WALLR_FZF_OPTS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# strip off only ID article listing
|
||||||
get_id() {
|
get_id() {
|
||||||
[ -z "$1" ] && exit 1
|
[ -z "$1" ] && exit 1
|
||||||
echo "$1" | head -n-1 | tail -n+2 | fzf "${WALLR_FZF_OPTS}" | sed -e 's/^ \+//' | cut -f1 -d' '
|
echo "$1" | sed -e 's/^ \+//' | cut -f1 -d' '
|
||||||
exit 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# grab content of article with ID passed in as parameter
|
# grab content of article with ID passed in as parameter
|
||||||
|
@ -54,14 +63,30 @@ check_missing_reqs() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open_in_pager() {
|
||||||
|
get_content "$1" | "$WALLR_READER"
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
arts=$(get_articles "$WALLR_FILTER")
|
# already selected an id
|
||||||
id="$(get_id "$arts")"
|
if [ -n "$WALLR_ARTICLE_SELECTED" ]; then
|
||||||
|
# relative selection
|
||||||
|
if printf "%s" "$WALLR_ARTICLE_SELECTED" | grep -qe '^+'; then
|
||||||
|
WALLR_FILTER="last"
|
||||||
|
newestid=$(get_id "$(get_articles)")
|
||||||
|
id=$((newestid - "$WALLR_ARTICLE_SELECTED"))
|
||||||
|
fi
|
||||||
|
# select with fuzzy menu
|
||||||
|
else
|
||||||
|
arts=$(get_articles "$WALLR_FILTER")
|
||||||
|
art="$(fuzzy_select "$arts")"
|
||||||
|
id="$(get_id "$art")"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$WALLR_READER" = "BROWSER" ]; then
|
if [ "$WALLR_READER" = "BROWSER" ]; then
|
||||||
open_link "$id"
|
open_link "$id"
|
||||||
else
|
else
|
||||||
get_content "$id" | "$WALLR_READER"
|
open_in_pager "$id"
|
||||||
if "$WALLR_MARKREAD"; then
|
if "$WALLR_MARKREAD"; then
|
||||||
mark_read "$id"
|
mark_read "$id"
|
||||||
fi
|
fi
|
||||||
|
@ -87,13 +112,18 @@ show_help() {
|
||||||
"" \
|
"" \
|
||||||
" -n List only unread articles." \
|
" -n List only unread articles." \
|
||||||
"" \
|
"" \
|
||||||
|
" -a [number] Do not list articles but directly open article number." \
|
||||||
|
" Takes either explicit number (1096 opens wallabag article" \
|
||||||
|
" with same id), or in the form of '+1' or '+102' which will" \
|
||||||
|
" open most recent counting backwards." \
|
||||||
|
"" \
|
||||||
" -q Do not mark articles opened as read." \
|
" -q Do not mark articles opened as read." \
|
||||||
"" \
|
"" \
|
||||||
" -h Print out this help." \
|
" -h Print out this help." \
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "h?qnorse" opt; do
|
while getopts "h?qnorsea:" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
h | \?)
|
h | \?)
|
||||||
show_help
|
show_help
|
||||||
|
@ -119,6 +149,9 @@ while getopts "h?qnorse" opt; do
|
||||||
q)
|
q)
|
||||||
WALLR_MARKREAD="false"
|
WALLR_MARKREAD="false"
|
||||||
;;
|
;;
|
||||||
|
a)
|
||||||
|
WALLR_ARTICLE_SELECTED="$OPTARG"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
Loading…
Reference in a new issue