[download]

local/bin/wikipedia-menu

   1 #!/bin/bash
   2 
   3 f=~/.cache/wikipedia-menu && touch $f
   4 s=$(tac $f | awk '!a[$0]++' | menu -i wikipedia)
   5 
   6 [[ $s ]] && echo "$s" >> $f || exit
   7 [[ ${s//[a-z]} != "$s" ]] && lang=en || lang=ru
   8 
   9 api="https://$lang.wikipedia.org/w/api.php"
  10 api+='?action=query&format=json&prop=extracts|info'
  11 api+='&generator=search&inprop=url&exsentences=1'
  12 api+='&exlimit=max&exintro&explaintext&redirects'
  13 
  14 while read i _; do
  15     chromium "$i" &
  16 done < <(
  17     while IFS=$'\t' read fullurl extract; do
  18         printf '%s\t%s\n' "$(echo -e "${fullurl//%/\\x}")" "$extract"
  19     done < <(
  20         curl -sd "gsrsearch=$s" $api |
  21         jq -r '.query.pages[] | [.fullurl, .extract] | @tsv'
  22     ) |
  23     column -ts $'\t' |
  24     menu -i wikipedia -p "$s" -l 15
  25 )