diff --git a/.vtsm/arch.json b/.vtsm/arch.json index 2c9debd..190b87d 100755 --- a/.vtsm/arch.json +++ b/.vtsm/arch.json @@ -1,5 +1,6 @@ { "alacritty": "$HOME/.config/alacritty/", + "bangs": "$HOME/.config/bangs/", "bin": "$HOME/.local/bin/", "bspwm": "$HOME/.config/bspwm/", "dunst": "$HOME/.config/dunst/", diff --git a/bin/bangs b/bin/bangs index da0466b..ccbe14f 100755 --- a/bin/bangs +++ b/bin/bangs @@ -66,6 +66,9 @@ const bangs_placeholder = "${BANGS_PLACEHOLDER:-{{{s}}}}" const bangs_format = / %start $bangs_prefix !space+ %end / const valid_bangs = %() const search_query = %() + +# Config file detection. +# Otherwise, we'll just use the default config. if test -f $config_file { json read :bangs < $config_file } else { @@ -75,7 +78,7 @@ if test -f $config_file { # Stolen from https://gist.github.com/cdown/1163649 and https://gist.github.com/cdown/1163649#gistcomment-1256298 proc urlencode(msg) { for (i in 0:len(msg)) { - var char = msg[i - 1] + var char = msg[i] case $char { [a-zA-Z0-9.~_-]) @@ -112,12 +115,15 @@ for i in @ARGV { } } -var query = $(printf "%s " @search_query) +var query = join(search_query, " ") +var encoded_query = $(urlencode $query) + warnf "Search query is '%s'" $query +warnf "Encoded form is '%s'" $encoded_query for bang in @valid_bangs { var metadata = bangs[bang] - var url = $(write -- ${metadata['url']} | sed --expression "s/${bangs_placeholder}/$(urlencode $query)/") + var url = $(write -- ${metadata['url']} | sed --expression "s/${bangs_placeholder}/${encoded_query}/") handlr open $url } diff --git a/bin/convert-opml-to-newsboat-urls b/bin/convert-opml-to-newsboat-urls index 7d7a33e..dcc637a 100755 --- a/bin/convert-opml-to-newsboat-urls +++ b/bin/convert-opml-to-newsboat-urls @@ -5,12 +5,16 @@ # It could also accept an OPML through stdin. import itertools +import fileinput from pathlib import Path import sys import xml.etree.ElementTree as ET -filename = sys.argv[1] -opml = ET.parse(filename) +if len(sys.argv) > 1: + opml = ET.parse(sys.argv[1]) +else: + opml = ET.fromstring(fileinput.input()) + for outline in opml.findall("body/outline"): categories = [category.strip("/") for category in outline.get("category", "").split(",") if category] print('{xmlUrl} "~{text}" {category}'.format(xmlUrl = outline.get("xmlUrl"), diff --git a/bin/split-album b/bin/split-album index 537bada..539036f 100755 --- a/bin/split-album +++ b/bin/split-album @@ -4,6 +4,8 @@ shopt --set strict:all const show_help = "A small script for splitting files into tracks, perfect for full album releases and audiobooks. +Based from Luke Smith's booksplit script +(https://raw.githubusercontent.com/LukeSmithxyz/voidrice/091d7e54c5c1ed77201ce1254aa2623a2801c9f2/.local/bin/booksplit). split-album [options...] [\$ALBUM_FILE \$TIMESTAMP_FILE] @@ -183,6 +185,7 @@ setvar output_data['extension'] = $EXTENSION const timestamp_regex = / %start digit{2,} ':' digit{2} ':' digit{2} <'.' digit+>? %end / var has_error = false +# Deserialize the given input into the chapters data. case $(file --mime-type --brief $timestamp_file) { "application/json") json read :chapters < $timestamp_file @@ -190,7 +193,7 @@ case $(file --mime-type --brief $timestamp_file) { ;; # Also cleans up the timestamp file with comments (i.e., lines starting with '#') and empty lines allowing for more commenting options. - # I just want to improve the timestamp format (a little bit). + # I just want to improve the timestamp format a little bit. "text/plain") sed --regexp-extended --expression '/^\s*$/d' --expression '/^#/d' $timestamp_file | while read --line { var chapter = {} @@ -227,6 +230,7 @@ for index in @(seq $[chapter_len]) { var filename = $(printf "%.2d-%s.%s" $index $(kebab-case ${chapter['title']}) $EXTENSION) setvar output_data['chapters'][index - 1]['file'] = filename + # Check for incorrect timestamp order. if (start > end and end is not null) { warnf '%s (start) is ahead compared to %s (end)' $start $end setvar has_error = true