dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

dmenu-wiki.sh (1448B)


      1 #!/bin/sh
      2 
      3 # Script using dmenu to search wikis
      4 
      5 # Example config:
      6 # `https://en.wikipedia.org/wiki,https://en.wikipedia.org/w/api.php,Wikipedia`
      7 # `https://wiki.factorio.com,https://wiki.factorio.com/api.php,Factorio Wiki`
      8 # Basically the format is base-url,api-url,name
      9 
     10 WIKI_FILE="$XDG_CONFIG_HOME/regexghost/wiki-list.csv"
     11 
     12 DMENU_RUNNER="$XDG_DATA_HOME/regexghost/wm-scripts/dmenu-runner.sh"
     13 
     14 wiki_to_search="$(cat "$WIKI_FILE" | cut -d "," -f 3- | "$DMENU_RUNNER" "Select wiki to search" -ix)"
     15 
     16 [ "$wiki_to_search" = "" ] && exit
     17 
     18 wiki_to_search=$((wiki_to_search+1))
     19 
     20 name="$(sed -n "${wiki_to_search}p" "$WIKI_FILE" | cut -d "," -f 3-)"
     21 url="$(sed -n "${wiki_to_search}p" "$WIKI_FILE" | cut -d "," -f 1)"
     22 api_url="$(sed -n "${wiki_to_search}p" "$WIKI_FILE" | cut -d "," -f 2)"
     23 
     24 search_term="$(echo "" | "$DMENU_RUNNER" "Enter search term (or none for homepage)" -pa)"
     25 
     26 status="$?"
     27 
     28 [ "$status" = "0" ] || exit
     29 
     30 if [ "$search_term" = "" ]; then
     31 	"$BROWSER" "$url"
     32 	exit
     33 fi
     34 
     35 search_term="$(echo "$search_term" | sed 's/ /+/g')"
     36 
     37 results="$(curl "${api_url}?action=query&format=json&list=search&srsearch=${search_term}" | sed 's/\\n//g')"
     38 
     39 titles="$(echo "$results" | jq -r .query.search.[].title)"
     40 
     41 if [ "$titles" = "" ] || [ "$title" = "null" ]; then
     42 	notify-send "No results"
     43 	exit
     44 fi
     45 
     46 selected_page="$(echo "$titles" | "$DMENU_RUNNER" "Select page" | sed 's/ /_/g')"
     47 
     48 [ "$selected_page" = "" ] && exit
     49 
     50 "$BROWSER" "${url}/${selected_page}"