Browse Source

Initial commit

Christoph Stelz 1 year ago
commit
83b85b96dd
3 changed files with 53 additions and 0 deletions
  1. 17 0
      README.md
  2. 33 0
      zeal_fzf.sh
  3. 3 0
      zeal_query.sh

+ 17 - 0
README.md

@@ -0,0 +1,17 @@
+# Zeal FZF
+
+[![asciicast](https://asciinema.org/a/p2PWqd5dyUnrjuDOe5mqg2ln2.svg)](https://asciinema.org/a/p2PWqd5dyUnrjuDOe5mqg2ln2)
+
+## Requirements
+
+* fzf
+* grep
+* w3m
+* sqlite3
+
+## Usage
+
+Simple command line interface for [Zeal Docs](https://zealdocs.org/).
+Make sure both scripts are inside your `$PATH` and you have downloaded a docset with the Zeal desktop application.
+
+You can then start the search interface with e.g. `zeal_fzf.sh Rust`.

+ 33 - 0
zeal_fzf.sh

@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+docset=$1
+if [[ -z $docset ]]; then
+    docsets=$(
+    ls ~/.local/share/Zeal/Zeal/docsets \
+        | grep -ioP ".*(?=.docset)" | tr '\n' ' ')
+    echo -e "Must supply docset as parameter.\nAvailable docsets: $docsets"
+    exit -1
+fi
+
+prefix="$HOME/.local/share/Zeal/Zeal/docsets/$docset.docset/Contents/Resources/Documents"
+if [[ ! -d "$prefix" ]]; then
+    echo Could not find docset $docset
+    exit -1
+fi
+url=$(echo "" | \
+fzf \
+    --bind "change:reload('$SCRIPT_DIR/zeal_query.sh' $1 '{q}')" \
+    --delimiter=";" \
+    --with-nth=1 \
+    --disabled |  \
+    grep -oP ';(.*<dash_entry.*>)?\K.*'
+)
+
+if [[ -n $url ]]; then
+    w3m $prefix/$url
+else
+    echo No result
+    echo $url
+    exit -1 
+fi

+ 3 - 0
zeal_query.sh

@@ -0,0 +1,3 @@
+docset=$1
+query=$2
+sqlite3 -separator ';' $HOME/.local/share/Zeal/Zeal/docsets/$docset.docset/Contents/Resources/docSet.dsidx "SELECT name, path FROM searchIndex WHERE name LIKE '%$2%';"