#!/usr/bin/env nix-shell #! nix-shell -i oil -p coreutils ripgrep handlr gnused xxd # A ripoff from Duckduckgo bangs. # Examples: # ``` # bangs hello there ~g ~aw # ``` # will open a search result page on Google and Arch Wiki proc usage() { cat <&2 printf "$format\\n" @msg } if (len(ARGV) == 0) { usage exit 0 } for i in @ARGV { write -- $i | rg --quiet $bangs_format || { push :search_query $i continue } var bang = $(write -- $i | sed --regexp-extended --expression "s/^${bangs_prefix}//") if (bang in bangs) { push :valid_bangs $bang warnf "%s will be used to search." $bang } else { warnf "%s is not found in the database." $bang } } var query = $(printf "%s " @search_query) warnf "Search query is '%s'" $query for bang in @valid_bangs { var metadata = bangs[bang] var url = $(write -- ${metadata['url']} | sed --expression "s/${bangs_placeholder}/$(urlencode $query)/") handlr open $url }